Skip to content

Commit ec5aac4

Browse files
committed
使用gofmt重新格式化
1 parent fbdb365 commit ec5aac4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3743
-3747
lines changed

builder/sql.go

Lines changed: 262 additions & 262 deletions
Large diffs are not rendered by default.

cache/metadata_cache.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,59 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package cache
1010

1111
import (
12-
"fmt"
13-
"github.com/xfali/gobatis/parsing/sqlparser"
14-
"sort"
15-
"strings"
16-
"sync"
12+
"fmt"
13+
"github.com/xfali/gobatis/parsing/sqlparser"
14+
"sort"
15+
"strings"
16+
"sync"
1717
)
1818

1919
type MetadataCache struct {
20-
cache map[MetadataCacheKey]*sqlparser.Metadata
21-
lock sync.Mutex
20+
cache map[MetadataCacheKey]*sqlparser.Metadata
21+
lock sync.Mutex
2222
}
2323

2424
type MetadataCacheKey string
2525

2626
var gMetadataCache = MetadataCache{
27-
cache: map[MetadataCacheKey]*sqlparser.Metadata{},
27+
cache: map[MetadataCacheKey]*sqlparser.Metadata{},
2828
}
2929

3030
func FindMetadata(key MetadataCacheKey) *sqlparser.Metadata {
31-
gMetadataCache.lock.Lock()
32-
defer gMetadataCache.lock.Unlock()
31+
gMetadataCache.lock.Lock()
32+
defer gMetadataCache.lock.Unlock()
3333

34-
return gMetadataCache.cache[key]
34+
return gMetadataCache.cache[key]
3535
}
3636

3737
func CacheMetadata(key MetadataCacheKey, data *sqlparser.Metadata) {
38-
gMetadataCache.lock.Lock()
39-
defer gMetadataCache.lock.Unlock()
38+
gMetadataCache.lock.Lock()
39+
defer gMetadataCache.lock.Unlock()
4040

41-
gMetadataCache.cache[key] = data
41+
gMetadataCache.cache[key] = data
4242
}
4343

4444
func CalcKey(sql string, params map[string]interface{}) MetadataCacheKey {
45-
buf := strings.Builder{}
46-
buf.WriteString(sql)
47-
list := make([]string, len(params))
48-
i := 0
49-
for k := range params {
50-
list[i] = k
51-
i++
52-
}
53-
sort.Slice(list, func(i, j int) bool {
54-
return list[i] > list[j]
55-
})
56-
for i := range list {
57-
buf.WriteString(list[i])
58-
buf.WriteString(fmt.Sprintf("%v", params[list[i]]))
59-
}
60-
return MetadataCacheKey(buf.String())
45+
buf := strings.Builder{}
46+
buf.WriteString(sql)
47+
list := make([]string, len(params))
48+
i := 0
49+
for k := range params {
50+
list[i] = k
51+
i++
52+
}
53+
sort.Slice(list, func(i, j int) bool {
54+
return list[i] > list[j]
55+
})
56+
for i := range list {
57+
buf.WriteString(list[i])
58+
buf.WriteString(fmt.Sprintf("%v", params[list[i]]))
59+
}
60+
return MetadataCacheKey(buf.String())
6161
}

common/define.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package common
@@ -15,7 +15,6 @@ package common
1515
// 打断迭代返回true
1616
type IterFunc func(idx int64, bean interface{}) bool
1717

18-
const(
19-
FIELD_NAME = "xfield"
18+
const (
19+
FIELD_NAME = "xfield"
2020
)
21-

common/result.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package common
1010

1111
type Result interface {
12-
LastInsertId() (int64, error)
13-
RowsAffected() (int64, error)
12+
LastInsertId() (int64, error)
13+
RowsAffected() (int64, error)
1414
}

connection/connection.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package connection
1010

1111
import (
12-
"context"
13-
"github.com/xfali/gobatis/common"
14-
"github.com/xfali/gobatis/reflection"
15-
"github.com/xfali/gobatis/statement"
12+
"context"
13+
"github.com/xfali/gobatis/common"
14+
"github.com/xfali/gobatis/reflection"
15+
"github.com/xfali/gobatis/statement"
1616
)
1717

1818
type Connection interface {
19-
Prepare(sql string) (statement.Statement, error)
20-
Query(ctx context.Context, result reflection.Object, sql string, params ...interface{}) error
21-
Exec(ctx context.Context, sql string, params ...interface{}) (common.Result, error)
19+
Prepare(sql string) (statement.Statement, error)
20+
Query(ctx context.Context, result reflection.Object, sql string, params ...interface{}) error
21+
Exec(ctx context.Context, sql string, params ...interface{}) (common.Result, error)
2222
}

connection/mysql_connection.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,68 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package connection
1010

1111
import (
12-
"context"
13-
"database/sql"
14-
"github.com/xfali/gobatis/common"
15-
"github.com/xfali/gobatis/errors"
16-
"github.com/xfali/gobatis/reflection"
17-
"github.com/xfali/gobatis/statement"
18-
"github.com/xfali/gobatis/util"
12+
"context"
13+
"database/sql"
14+
"github.com/xfali/gobatis/common"
15+
"github.com/xfali/gobatis/errors"
16+
"github.com/xfali/gobatis/reflection"
17+
"github.com/xfali/gobatis/statement"
18+
"github.com/xfali/gobatis/util"
1919
)
2020

2121
type MysqlConnection sql.DB
2222
type MysqlStatement sql.Stmt
2323

2424
func (c *MysqlConnection) Prepare(sqlStr string) (statement.Statement, error) {
25-
db := (*sql.DB)(c)
26-
s, err := db.Prepare(sqlStr)
27-
if err != nil {
28-
return nil, errors.CONNECTION_PREPARE_ERROR
29-
}
30-
return (*MysqlStatement)(s), nil
25+
db := (*sql.DB)(c)
26+
s, err := db.Prepare(sqlStr)
27+
if err != nil {
28+
return nil, errors.CONNECTION_PREPARE_ERROR
29+
}
30+
return (*MysqlStatement)(s), nil
3131
}
3232

3333
func (c *MysqlConnection) Query(ctx context.Context, result reflection.Object, sqlStr string, params ...interface{}) error {
34-
db := (*sql.DB)(c)
35-
rows, err := db.QueryContext(ctx, sqlStr, params...)
36-
if err != nil {
37-
return errors.STATEMENT_QUERY_ERROR
38-
}
39-
defer rows.Close()
34+
db := (*sql.DB)(c)
35+
rows, err := db.QueryContext(ctx, sqlStr, params...)
36+
if err != nil {
37+
return errors.STATEMENT_QUERY_ERROR
38+
}
39+
defer rows.Close()
4040

41-
util.ScanRows(rows, result)
42-
return nil
41+
util.ScanRows(rows, result)
42+
return nil
4343
}
4444

4545
func (c *MysqlConnection) Exec(ctx context.Context, sqlStr string, params ...interface{}) (common.Result, error) {
46-
db := (*sql.DB)(c)
47-
return db.ExecContext(ctx, sqlStr, params...)
46+
db := (*sql.DB)(c)
47+
return db.ExecContext(ctx, sqlStr, params...)
4848
}
4949

5050
func (s *MysqlStatement) Query(ctx context.Context, result reflection.Object, params ...interface{}) error {
51-
stmt := (*sql.Stmt)(s)
52-
rows, err := stmt.QueryContext(ctx, params...)
53-
if err != nil {
54-
return errors.STATEMENT_QUERY_ERROR
55-
}
56-
defer rows.Close()
51+
stmt := (*sql.Stmt)(s)
52+
rows, err := stmt.QueryContext(ctx, params...)
53+
if err != nil {
54+
return errors.STATEMENT_QUERY_ERROR
55+
}
56+
defer rows.Close()
5757

58-
util.ScanRows(rows, result)
59-
return nil
58+
util.ScanRows(rows, result)
59+
return nil
6060
}
6161

6262
func (s *MysqlStatement) Exec(ctx context.Context, params ...interface{}) (common.Result, error) {
63-
stmt := (*sql.Stmt)(s)
64-
return stmt.ExecContext(ctx, params...)
63+
stmt := (*sql.Stmt)(s)
64+
return stmt.ExecContext(ctx, params...)
6565
}
6666

6767
func (s *MysqlStatement) Close() {
68-
stmt := (*sql.Stmt)(s)
69-
stmt.Close()
68+
stmt := (*sql.Stmt)(s)
69+
stmt.Close()
7070
}

datasource/datasource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package datasource
1010

1111
type DataSource interface {
12-
DriverName() string
13-
Url() string
12+
DriverName() string
13+
Url() string
1414
}

datasource/mysql_datasource.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package datasource
1010

1111
import "fmt"
1212

1313
type MysqlDataSource struct {
14-
Host string
15-
Port int
16-
DBName string
17-
Username string
18-
Password string
19-
Charset string
14+
Host string
15+
Port int
16+
DBName string
17+
Username string
18+
Password string
19+
Charset string
2020
}
2121

2222
func (ds *MysqlDataSource) DriverName() string {
23-
return "mysql"
23+
return "mysql"
2424
}
2525

2626
func (ds *MysqlDataSource) Url() string {
27-
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s", ds.Username, ds.Password, ds.Host, ds.Port, ds.DBName, ds.Charset)
27+
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=%s", ds.Username, ds.Password, ds.Host, ds.Port, ds.DBName, ds.Charset)
2828
}

errors/errcode.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package errors
1010

1111
import "fmt"
1212

1313
type ErrCode struct {
14-
Code string `json:"code"`
15-
Message string `json:"msg"`
16-
fmtErr string `json:"-"`
14+
Code string `json:"code"`
15+
Message string `json:"msg"`
16+
fmtErr string `json:"-"`
1717
}
1818

1919
var PARSE_MODEL_TABLEINFO_FAILED *ErrCode = New("11001", "Parse Model's table info failed")
@@ -51,14 +51,14 @@ var RESULT_SELECT_EMPTY_VALUE *ErrCode = New("31005", "select return empty value
5151
var RESULT_SET_VALUE_FAILED *ErrCode = New("31006", "result set value failed")
5252

5353
func New(code, message string) *ErrCode {
54-
ret := &ErrCode{
55-
Code: code,
56-
Message: message,
57-
fmtErr: fmt.Sprintf("{ \"code\" : \"%s\", \"msg\" : \"%s\" }", code, message),
58-
}
59-
return ret
54+
ret := &ErrCode{
55+
Code: code,
56+
Message: message,
57+
fmtErr: fmt.Sprintf("{ \"code\" : \"%s\", \"msg\" : \"%s\" }", code, message),
58+
}
59+
return ret
6060
}
6161

6262
func (e *ErrCode) Error() string {
63-
return e.fmtErr
63+
return e.fmtErr
6464
}

executor/executor.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
* All right reserved.
44
* @author xiongfa.li
55
* @version V1.0
6-
* Description:
6+
* Description:
77
*/
88

99
package executor
1010

1111
import (
12-
"context"
13-
"github.com/xfali/gobatis/common"
14-
"github.com/xfali/gobatis/reflection"
12+
"context"
13+
"github.com/xfali/gobatis/common"
14+
"github.com/xfali/gobatis/reflection"
1515
)
1616

1717
type Executor interface {
18-
Close(rollback bool)
18+
Close(rollback bool)
1919

20-
Query(ctx context.Context, result reflection.Object, sql string, params ... interface{}) error
20+
Query(ctx context.Context, result reflection.Object, sql string, params ...interface{}) error
2121

22-
Exec(ctx context.Context, sql string, params ... interface{}) (common.Result, error)
22+
Exec(ctx context.Context, sql string, params ...interface{}) (common.Result, error)
2323

24-
Begin() error
24+
Begin() error
2525

26-
Commit(require bool) error
26+
Commit(require bool) error
2727

28-
Rollback(require bool) error
28+
Rollback(require bool) error
2929
}

0 commit comments

Comments
 (0)