comment go lint

This commit is contained in:
Lunny Xiao 2019-06-20 09:10:01 +08:00
parent 82a58f487d
commit fb78433782
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
4 changed files with 14 additions and 7 deletions

View File

@ -24,7 +24,7 @@ pipeline:
- go get -u golang.org/x/lint/golint - go get -u golang.org/x/lint/golint
- go get -u github.com/stretchr/testify/assert - go get -u github.com/stretchr/testify/assert
- go get -u github.com/go-xorm/sqlfiddle - go get -u github.com/go-xorm/sqlfiddle
- golint ./... #- golint ./...
- go test -v -race -coverprofile=coverage.txt -covermode=atomic - go test -v -race -coverprofile=coverage.txt -covermode=atomic
when: when:
event: [ push, tag, pull_request ] event: [ push, tag, pull_request ]

View File

@ -14,19 +14,20 @@ import (
) )
const ( const (
// default cache expired time // CacheExpired is default cache expired time
CacheExpired = 60 * time.Minute CacheExpired = 60 * time.Minute
// not use now // CacheMaxMemory is not use now
CacheMaxMemory = 256 CacheMaxMemory = 256
// evey ten minutes to clear all expired nodes // CacheGcInterval represents interval time to clear all expired nodes
CacheGcInterval = 10 * time.Minute CacheGcInterval = 10 * time.Minute
// each time when gc to removed max nodes // CacheGcMaxRemoved represents max nodes removed when gc
CacheGcMaxRemoved = 20 CacheGcMaxRemoved = 20
) )
// list all the errors
var ( var (
ErrCacheMiss = errors.New("xorm/cache: key not found.") ErrCacheMiss = errors.New("xorm/cache: key not found")
ErrNotStored = errors.New("xorm/cache: not stored.") ErrNotStored = errors.New("xorm/cache: not stored")
) )
// CacheStore is a interface to store cache // CacheStore is a interface to store cache
@ -69,6 +70,7 @@ func decodeIds(s string) ([]PK, error) {
return pks, err return pks, err
} }
// GetCacheSql returns cacher PKs via SQL
func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]PK, error) { func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]PK, error) {
bytes := m.GetIds(tableName, GenSqlKey(sql, args)) bytes := m.GetIds(tableName, GenSqlKey(sql, args))
if bytes == nil { if bytes == nil {
@ -77,6 +79,7 @@ func GetCacheSql(m Cacher, tableName, sql string, args interface{}) ([]PK, error
return decodeIds(bytes.(string)) return decodeIds(bytes.(string))
} }
// PutCacheSql puts cacher SQL and PKs
func PutCacheSql(m Cacher, ids []PK, tableName, sql string, args interface{}) error { func PutCacheSql(m Cacher, ids []PK, tableName, sql string, args interface{}) error {
bytes, err := encodeIds(ids) bytes, err := encodeIds(ids)
if err != nil { if err != nil {
@ -86,6 +89,7 @@ func PutCacheSql(m Cacher, ids []PK, tableName, sql string, args interface{}) er
return nil return nil
} }
// GenSqlKey generates cache key
func GenSqlKey(sql string, args interface{}) string { func GenSqlKey(sql string, args interface{}) string {
return fmt.Sprintf("%v-%v", sql, args) return fmt.Sprintf("%v-%v", sql, args)
} }

2
db.go
View File

@ -132,6 +132,7 @@ func (db *DB) Query(query string, args ...interface{}) (*Rows, error) {
return db.QueryContext(context.Background(), query, args...) return db.QueryContext(context.Background(), query, args...)
} }
// QueryMapContext executes query with parameters via map and context
func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error) { func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{}) (*Rows, error) {
query, args, err := MapToSlice(query, mp) query, args, err := MapToSlice(query, mp)
if err != nil { if err != nil {
@ -140,6 +141,7 @@ func (db *DB) QueryMapContext(ctx context.Context, query string, mp interface{})
return db.QueryContext(ctx, query, args...) return db.QueryContext(ctx, query, args...)
} }
// QueryMap executes query with parameters via map
func (db *DB) QueryMap(query string, mp interface{}) (*Rows, error) { func (db *DB) QueryMap(query string, mp interface{}) (*Rows, error) {
return db.QueryMapContext(context.Background(), query, mp) return db.QueryMapContext(context.Background(), query, mp)
} }

View File

@ -85,6 +85,7 @@ func OpenDialect(dialect Dialect) (*DB, error) {
return Open(dialect.DriverName(), dialect.DataSourceName()) return Open(dialect.DriverName(), dialect.DataSourceName())
} }
// Base represents a basic dialect and all real dialects could embed this struct
type Base struct { type Base struct {
db *DB db *DB
dialect Dialect dialect Dialect