Refine Comments : admin/profile.go,bean/mock.go,config/global.go... (#5009)
* Refine Comments * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go
This commit is contained in:
parent
2c506f7c2b
commit
49be2581d1
16
adapter/cache/cache.go
vendored
16
adapter/cache/cache.go
vendored
@ -47,23 +47,23 @@ import (
|
|||||||
// c.Incr("counter") // now is 2
|
// c.Incr("counter") // now is 2
|
||||||
// count := c.Get("counter").(int)
|
// count := c.Get("counter").(int)
|
||||||
type Cache interface {
|
type Cache interface {
|
||||||
// get cached value by key.
|
// Get will get cached value by key.
|
||||||
Get(key string) interface{}
|
Get(key string) interface{}
|
||||||
// GetMulti is a batch version of Get.
|
// GetMulti is a batch version of Get.
|
||||||
GetMulti(keys []string) []interface{}
|
GetMulti(keys []string) []interface{}
|
||||||
// set cached value with key and expire time.
|
// Put will set cached value with key and expire time.
|
||||||
Put(key string, val interface{}, timeout time.Duration) error
|
Put(key string, val interface{}, timeout time.Duration) error
|
||||||
// delete cached value by key.
|
// Delete will delete cached value by key.
|
||||||
Delete(key string) error
|
Delete(key string) error
|
||||||
// increase cached int value by key, as a counter.
|
// Incr will increase cached int value by key, as a counter.
|
||||||
Incr(key string) error
|
Incr(key string) error
|
||||||
// decrease cached int value by key, as a counter.
|
// Decr will decrease cached int value by key, as a counter.
|
||||||
Decr(key string) error
|
Decr(key string) error
|
||||||
// check if cached value exists or not.
|
// IsExist can check if cached value exists or not.
|
||||||
IsExist(key string) bool
|
IsExist(key string) bool
|
||||||
// clear all cache.
|
// ClearAll will clear all cache.
|
||||||
ClearAll() error
|
ClearAll() error
|
||||||
// start gc routine based on config string settings.
|
// StartAndGC will start gc routine based on config string settings.
|
||||||
StartAndGC(config string) error
|
StartAndGC(config string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,5 +12,5 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// used to keep compatible with v1.x
|
// Package adapter used to keep compatible with v1.x
|
||||||
package adapter
|
package adapter
|
||||||
|
|||||||
@ -158,7 +158,7 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
|
|||||||
(*logs.BeeLogger)(bl).EnableFuncCallDepth(b)
|
(*logs.BeeLogger)(bl).EnableFuncCallDepth(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set prefix
|
// SetPrefix will set prefix
|
||||||
func (bl *BeeLogger) SetPrefix(s string) {
|
func (bl *BeeLogger) SetPrefix(s string) {
|
||||||
(*logs.BeeLogger)(bl).SetPrefix(s)
|
(*logs.BeeLogger)(bl).SetPrefix(s)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build go1.8
|
||||||
// +build go1.8
|
// +build go1.8
|
||||||
|
|
||||||
// Package orm provide ORM for MySQL/PostgreSQL/sqlite
|
// Package orm provide ORM for MySQL/PostgreSQL/sqlite
|
||||||
@ -92,7 +93,7 @@ type ormer struct {
|
|||||||
|
|
||||||
var _ Ormer = new(ormer)
|
var _ Ormer = new(ormer)
|
||||||
|
|
||||||
// read data to model
|
// Read read data to model
|
||||||
func (o *ormer) Read(md interface{}, cols ...string) error {
|
func (o *ormer) Read(md interface{}, cols ...string) error {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.Read(md, cols...)
|
return o.txDelegate.Read(md, cols...)
|
||||||
@ -100,7 +101,7 @@ func (o *ormer) Read(md interface{}, cols ...string) error {
|
|||||||
return o.delegate.Read(md, cols...)
|
return o.delegate.Read(md, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read data to model, like Read(), but use "SELECT FOR UPDATE" form
|
// ReadForUpdate read data to model, like Read(), but use "SELECT FOR UPDATE" form
|
||||||
func (o *ormer) ReadForUpdate(md interface{}, cols ...string) error {
|
func (o *ormer) ReadForUpdate(md interface{}, cols ...string) error {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.ReadForUpdate(md, cols...)
|
return o.txDelegate.ReadForUpdate(md, cols...)
|
||||||
@ -108,7 +109,7 @@ func (o *ormer) ReadForUpdate(md interface{}, cols ...string) error {
|
|||||||
return o.delegate.ReadForUpdate(md, cols...)
|
return o.delegate.ReadForUpdate(md, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to read a row from the database, or insert one if it doesn't exist
|
// ReadOrCreate Try to read a row from the database, or insert one if it doesn't exist
|
||||||
func (o *ormer) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error) {
|
func (o *ormer) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error) {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.ReadOrCreate(md, col1, cols...)
|
return o.txDelegate.ReadOrCreate(md, col1, cols...)
|
||||||
@ -116,7 +117,7 @@ func (o *ormer) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool,
|
|||||||
return o.delegate.ReadOrCreate(md, col1, cols...)
|
return o.delegate.ReadOrCreate(md, col1, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert model data to database
|
// Insert will insert model data to database
|
||||||
func (o *ormer) Insert(md interface{}) (int64, error) {
|
func (o *ormer) Insert(md interface{}) (int64, error) {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.Insert(md)
|
return o.txDelegate.Insert(md)
|
||||||
@ -124,7 +125,7 @@ func (o *ormer) Insert(md interface{}) (int64, error) {
|
|||||||
return o.delegate.Insert(md)
|
return o.delegate.Insert(md)
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert some models to database
|
// InsertMulti will insert some models to database
|
||||||
func (o *ormer) InsertMulti(bulk int, mds interface{}) (int64, error) {
|
func (o *ormer) InsertMulti(bulk int, mds interface{}) (int64, error) {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.InsertMulti(bulk, mds)
|
return o.txDelegate.InsertMulti(bulk, mds)
|
||||||
@ -140,7 +141,7 @@ func (o *ormer) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int
|
|||||||
return o.delegate.InsertOrUpdate(md, colConflitAndArgs...)
|
return o.delegate.InsertOrUpdate(md, colConflitAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update model to database.
|
// Update will update model to database.
|
||||||
// cols set the columns those want to update.
|
// cols set the columns those want to update.
|
||||||
func (o *ormer) Update(md interface{}, cols ...string) (int64, error) {
|
func (o *ormer) Update(md interface{}, cols ...string) (int64, error) {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
@ -149,7 +150,7 @@ func (o *ormer) Update(md interface{}, cols ...string) (int64, error) {
|
|||||||
return o.delegate.Update(md, cols...)
|
return o.delegate.Update(md, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete model in database
|
// Delete delete model in database
|
||||||
// cols shows the delete conditions values read from. default is pk
|
// cols shows the delete conditions values read from. default is pk
|
||||||
func (o *ormer) Delete(md interface{}, cols ...string) (int64, error) {
|
func (o *ormer) Delete(md interface{}, cols ...string) (int64, error) {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
@ -158,7 +159,7 @@ func (o *ormer) Delete(md interface{}, cols ...string) (int64, error) {
|
|||||||
return o.delegate.Delete(md, cols...)
|
return o.delegate.Delete(md, cols...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a models to models queryer
|
// QueryM2M create a models to models queryer
|
||||||
func (o *ormer) QueryM2M(md interface{}, name string) QueryM2Mer {
|
func (o *ormer) QueryM2M(md interface{}, name string) QueryM2Mer {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.QueryM2M(md, name)
|
return o.txDelegate.QueryM2M(md, name)
|
||||||
@ -166,7 +167,7 @@ func (o *ormer) QueryM2M(md interface{}, name string) QueryM2Mer {
|
|||||||
return o.delegate.QueryM2M(md, name)
|
return o.delegate.QueryM2M(md, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// load related models to md model.
|
// LoadRelated load related models to md model.
|
||||||
// args are limit, offset int and order string.
|
// args are limit, offset int and order string.
|
||||||
//
|
//
|
||||||
// example:
|
// example:
|
||||||
@ -200,7 +201,7 @@ func (o *ormer) LoadRelated(md interface{}, name string, args ...interface{}) (i
|
|||||||
return o.delegate.LoadRelated(md, name, kvs...)
|
return o.delegate.LoadRelated(md, name, kvs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a QuerySeter for table operations.
|
// QueryTable return a QuerySeter for table operations.
|
||||||
// table name can be string or struct.
|
// table name can be string or struct.
|
||||||
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
|
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
|
||||||
func (o *ormer) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
|
func (o *ormer) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
|
||||||
@ -210,7 +211,7 @@ func (o *ormer) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) {
|
|||||||
return o.delegate.QueryTable(ptrStructOrTableName)
|
return o.delegate.QueryTable(ptrStructOrTableName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch to another registered database driver by given name.
|
// Using switch to another registered database driver by given name.
|
||||||
func (o *ormer) Using(name string) error {
|
func (o *ormer) Using(name string) error {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return ErrTxHasBegan
|
return ErrTxHasBegan
|
||||||
@ -219,7 +220,7 @@ func (o *ormer) Using(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin transaction
|
// Begin will begin transaction
|
||||||
func (o *ormer) Begin() error {
|
func (o *ormer) Begin() error {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return ErrTxHasBegan
|
return ErrTxHasBegan
|
||||||
@ -240,7 +241,7 @@ func (o *ormer) BeginTx(ctx context.Context, opts *sql.TxOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit transaction
|
// Commit will commit transaction
|
||||||
func (o *ormer) Commit() error {
|
func (o *ormer) Commit() error {
|
||||||
if !o.isTx {
|
if !o.isTx {
|
||||||
return ErrTxDone
|
return ErrTxDone
|
||||||
@ -255,7 +256,7 @@ func (o *ormer) Commit() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// rollback transaction
|
// Rollback will rollback transaction
|
||||||
func (o *ormer) Rollback() error {
|
func (o *ormer) Rollback() error {
|
||||||
if !o.isTx {
|
if !o.isTx {
|
||||||
return ErrTxDone
|
return ErrTxDone
|
||||||
@ -270,7 +271,7 @@ func (o *ormer) Rollback() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a raw query seter for raw sql string.
|
// Raw return a raw query seter for raw sql string.
|
||||||
func (o *ormer) Raw(query string, args ...interface{}) RawSeter {
|
func (o *ormer) Raw(query string, args ...interface{}) RawSeter {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.Raw(query, args...)
|
return o.txDelegate.Raw(query, args...)
|
||||||
@ -278,7 +279,7 @@ func (o *ormer) Raw(query string, args ...interface{}) RawSeter {
|
|||||||
return o.delegate.Raw(query, args...)
|
return o.delegate.Raw(query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return current using database Driver
|
// Driver return current using database Driver
|
||||||
func (o *ormer) Driver() Driver {
|
func (o *ormer) Driver() Driver {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.Driver()
|
return o.txDelegate.Driver()
|
||||||
@ -286,7 +287,7 @@ func (o *ormer) Driver() Driver {
|
|||||||
return o.delegate.Driver()
|
return o.delegate.Driver()
|
||||||
}
|
}
|
||||||
|
|
||||||
// return sql.DBStats for current database
|
// DBStats return sql.DBStats for current database
|
||||||
func (o *ormer) DBStats() *sql.DBStats {
|
func (o *ormer) DBStats() *sql.DBStats {
|
||||||
if o.isTx {
|
if o.isTx {
|
||||||
return o.txDelegate.DBStats()
|
return o.txDelegate.DBStats()
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import (
|
|||||||
// Log implement the log.Logger
|
// Log implement the log.Logger
|
||||||
type Log orm.Log
|
type Log orm.Log
|
||||||
|
|
||||||
// costomer log func
|
// LogFunc is costomer log func
|
||||||
var LogFunc = orm.LogFunc
|
var LogFunc = orm.LogFunc
|
||||||
|
|
||||||
// NewLog set io.Writer to create a Logger.
|
// NewLog set io.Writer to create a Logger.
|
||||||
|
|||||||
@ -35,7 +35,7 @@ type Fielder orm.Fielder
|
|||||||
|
|
||||||
// Ormer define the orm interface
|
// Ormer define the orm interface
|
||||||
type Ormer interface {
|
type Ormer interface {
|
||||||
// read data to model
|
// Read read data to model
|
||||||
// for example:
|
// for example:
|
||||||
// this will find User by Id field
|
// this will find User by Id field
|
||||||
// u = &User{Id: user.Id}
|
// u = &User{Id: user.Id}
|
||||||
@ -44,25 +44,25 @@ type Ormer interface {
|
|||||||
// u = &User{UserName: "astaxie", Password: "pass"}
|
// u = &User{UserName: "astaxie", Password: "pass"}
|
||||||
// err = Ormer.Read(u, "UserName")
|
// err = Ormer.Read(u, "UserName")
|
||||||
Read(md interface{}, cols ...string) error
|
Read(md interface{}, cols ...string) error
|
||||||
// Like Read(), but with "FOR UPDATE" clause, useful in transaction.
|
// ReadForUpdate Like Read(), but with "FOR UPDATE" clause, useful in transaction.
|
||||||
// Some databases are not support this feature.
|
// Some databases are not support this feature.
|
||||||
ReadForUpdate(md interface{}, cols ...string) error
|
ReadForUpdate(md interface{}, cols ...string) error
|
||||||
// Try to read a row from the database, or insert one if it doesn't exist
|
// ReadOrCreate Try to read a row from the database, or insert one if it doesn't exist
|
||||||
ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error)
|
ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error)
|
||||||
// insert model data to database
|
// Insert will insert model data to database
|
||||||
// for example:
|
// for example:
|
||||||
// user := new(User)
|
// user := new(User)
|
||||||
// id, err = Ormer.Insert(user)
|
// id, err = Ormer.Insert(user)
|
||||||
// user must be a pointer and Insert will set user's pk field
|
// user must be a pointer and Insert will set user's pk field
|
||||||
Insert(interface{}) (int64, error)
|
Insert(interface{}) (int64, error)
|
||||||
// mysql:InsertOrUpdate(model) or InsertOrUpdate(model,"colu=colu+value")
|
// InsertOrUpdate(model,"colu=colu+value") or mysql:InsertOrUpdate(model)
|
||||||
// if colu type is integer : can use(+-*/), string : convert(colu,"value")
|
// if colu type is integer : can use(+-*/), string : convert(colu,"value")
|
||||||
// postgres: InsertOrUpdate(model,"conflictColumnName") or InsertOrUpdate(model,"conflictColumnName","colu=colu+value")
|
// postgres: InsertOrUpdate(model,"conflictColumnName") or InsertOrUpdate(model,"conflictColumnName","colu=colu+value")
|
||||||
// if colu type is integer : can use(+-*/), string : colu || "value"
|
// if colu type is integer : can use(+-*/), string : colu || "value"
|
||||||
InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error)
|
InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error)
|
||||||
// insert some models to database
|
// InsertMulti insert some models to database
|
||||||
InsertMulti(bulk int, mds interface{}) (int64, error)
|
InsertMulti(bulk int, mds interface{}) (int64, error)
|
||||||
// update model to database.
|
// Update update model to database.
|
||||||
// cols set the columns those want to update.
|
// cols set the columns those want to update.
|
||||||
// find model by Id(pk) field and update columns specified by fields, if cols is null then update all columns
|
// find model by Id(pk) field and update columns specified by fields, if cols is null then update all columns
|
||||||
// for example:
|
// for example:
|
||||||
@ -72,9 +72,9 @@ type Ormer interface {
|
|||||||
// user.Extra.Data = "orm"
|
// user.Extra.Data = "orm"
|
||||||
// num, err = Ormer.Update(&user, "Langs", "Extra")
|
// num, err = Ormer.Update(&user, "Langs", "Extra")
|
||||||
Update(md interface{}, cols ...string) (int64, error)
|
Update(md interface{}, cols ...string) (int64, error)
|
||||||
// delete model in database
|
// Delete delete model in database
|
||||||
Delete(md interface{}, cols ...string) (int64, error)
|
Delete(md interface{}, cols ...string) (int64, error)
|
||||||
// load related models to md model.
|
// LoadRelated load related models to md model.
|
||||||
// args are limit, offset int and order string.
|
// args are limit, offset int and order string.
|
||||||
//
|
//
|
||||||
// example:
|
// example:
|
||||||
@ -87,25 +87,25 @@ type Ormer interface {
|
|||||||
// args[3] string order for example : "-Id"
|
// args[3] string order for example : "-Id"
|
||||||
// make sure the relation is defined in model struct tags.
|
// make sure the relation is defined in model struct tags.
|
||||||
LoadRelated(md interface{}, name string, args ...interface{}) (int64, error)
|
LoadRelated(md interface{}, name string, args ...interface{}) (int64, error)
|
||||||
// create a models to models queryer
|
// QueryM2M create a models to models queryer
|
||||||
// for example:
|
// for example:
|
||||||
// post := Post{Id: 4}
|
// post := Post{Id: 4}
|
||||||
// m2m := Ormer.QueryM2M(&post, "Tags")
|
// m2m := Ormer.QueryM2M(&post, "Tags")
|
||||||
QueryM2M(md interface{}, name string) QueryM2Mer
|
QueryM2M(md interface{}, name string) QueryM2Mer
|
||||||
// return a QuerySeter for table operations.
|
// QueryTable return a QuerySeter for table operations.
|
||||||
// table name can be string or struct.
|
// table name can be string or struct.
|
||||||
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
|
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
|
||||||
QueryTable(ptrStructOrTableName interface{}) QuerySeter
|
QueryTable(ptrStructOrTableName interface{}) QuerySeter
|
||||||
// switch to another registered database driver by given name.
|
// switch to another registered database driver by given name.
|
||||||
Using(name string) error
|
Using(name string) error
|
||||||
// begin transaction
|
// Begin begin transaction
|
||||||
// for example:
|
// for example:
|
||||||
// o := NewOrm()
|
// o := NewOrm()
|
||||||
// err := o.Begin()
|
// err := o.Begin()
|
||||||
// ...
|
// ...
|
||||||
// err = o.Rollback()
|
// err = o.Rollback()
|
||||||
Begin() error
|
Begin() error
|
||||||
// begin transaction with provided context and option
|
// BeginTx begin transaction with provided context and option
|
||||||
// the provided context is used until the transaction is committed or rolled back.
|
// the provided context is used until the transaction is committed or rolled back.
|
||||||
// if the context is canceled, the transaction will be rolled back.
|
// if the context is canceled, the transaction will be rolled back.
|
||||||
// the provided TxOptions is optional and may be nil if defaults should be used.
|
// the provided TxOptions is optional and may be nil if defaults should be used.
|
||||||
@ -116,11 +116,11 @@ type Ormer interface {
|
|||||||
// ...
|
// ...
|
||||||
// err = o.Rollback()
|
// err = o.Rollback()
|
||||||
BeginTx(ctx context.Context, opts *sql.TxOptions) error
|
BeginTx(ctx context.Context, opts *sql.TxOptions) error
|
||||||
// commit transaction
|
// Commit commit transaction
|
||||||
Commit() error
|
Commit() error
|
||||||
// rollback transaction
|
// Rollback rollback transaction
|
||||||
Rollback() error
|
Rollback() error
|
||||||
// return a raw query seter for raw sql string.
|
// Raw return a raw query seter for raw sql string.
|
||||||
// for example:
|
// for example:
|
||||||
// ormer.Raw("UPDATE `user` SET `user_name` = ? WHERE `user_name` = ?", "slene", "testing").Exec()
|
// ormer.Raw("UPDATE `user` SET `user_name` = ? WHERE `user_name` = ?", "slene", "testing").Exec()
|
||||||
// // update user testing's name to slene
|
// // update user testing's name to slene
|
||||||
|
|||||||
@ -246,7 +246,7 @@ func camelString(s string) string {
|
|||||||
|
|
||||||
type argString []string
|
type argString []string
|
||||||
|
|
||||||
// get string by index from string slice
|
// Get will get string by index from string slice
|
||||||
func (a argString) Get(i int, args ...string) (r string) {
|
func (a argString) Get(i int, args ...string) (r string) {
|
||||||
if i >= 0 && i < len(a) {
|
if i >= 0 && i < len(a) {
|
||||||
r = a[i]
|
r = a[i]
|
||||||
@ -258,7 +258,7 @@ func (a argString) Get(i int, args ...string) (r string) {
|
|||||||
|
|
||||||
type argInt []int
|
type argInt []int
|
||||||
|
|
||||||
// get int by index from int slice
|
// Get will get int by index from int slice
|
||||||
func (a argInt) Get(i int, args ...int) (r int) {
|
func (a argInt) Get(i int, args ...int) (r int) {
|
||||||
if i >= 0 && i < len(a) {
|
if i >= 0 && i < len(a) {
|
||||||
r = a[i]
|
r = a[i]
|
||||||
@ -269,13 +269,13 @@ func (a argInt) Get(i int, args ...int) (r int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse time to string with location
|
// timeParse parse time to string with location
|
||||||
func timeParse(dateString, format string) (time.Time, error) {
|
func timeParse(dateString, format string) (time.Time, error) {
|
||||||
tp, err := time.ParseInLocation(format, dateString, DefaultTimeLoc)
|
tp, err := time.ParseInLocation(format, dateString, DefaultTimeLoc)
|
||||||
return tp, err
|
return tp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// get pointer indirect type
|
// indirectType get pointer indirect type
|
||||||
func indirectType(v reflect.Type) reflect.Type {
|
func indirectType(v reflect.Type) reflect.Type {
|
||||||
switch v.Kind() {
|
switch v.Kind() {
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
|
|||||||
@ -144,7 +144,7 @@ func avg(items []time.Duration) time.Duration {
|
|||||||
return time.Duration(int64(sum) / int64(len(items)))
|
return time.Duration(int64(sum) / int64(len(items)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// format bytes number friendly
|
// toH format bytes number friendly
|
||||||
func toH(bytes uint64) string {
|
func toH(bytes uint64) string {
|
||||||
switch {
|
switch {
|
||||||
case bytes < 1024:
|
case bytes < 1024:
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// the mock object must be pointer of struct
|
// Mock have a mock object ,it must be pointer of struct
|
||||||
// the element in mock object can be slices, structures, basic data types, pointers and interface
|
// the element in mock object can be slices, structures, basic data types, pointers and interface
|
||||||
func Mock(v interface{}) (err error) {
|
func Mock(v interface{}) (err error) {
|
||||||
pv := reflect.ValueOf(v)
|
pv := reflect.ValueOf(v)
|
||||||
|
|||||||
@ -28,17 +28,17 @@ func InitGlobalInstance(name string, cfg string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// support section::key type in given key when using ini type.
|
// Set support section::key type in given key when using ini type.
|
||||||
func Set(key, val string) error {
|
func Set(key, val string) error {
|
||||||
return globalInstance.Set(key, val)
|
return globalInstance.Set(key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
// String support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
||||||
func String(key string) (string, error) {
|
func String(key string) (string, error) {
|
||||||
return globalInstance.String(key)
|
return globalInstance.String(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get string slice
|
// Strings will get string slice
|
||||||
func Strings(key string) ([]string, error) {
|
func Strings(key string) ([]string, error) {
|
||||||
return globalInstance.Strings(key)
|
return globalInstance.Strings(key)
|
||||||
}
|
}
|
||||||
@ -59,12 +59,12 @@ func Float(key string) (float64, error) {
|
|||||||
return globalInstance.Float(key)
|
return globalInstance.Float(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
// DefaultString support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
||||||
func DefaultString(key string, defaultVal string) string {
|
func DefaultString(key string, defaultVal string) string {
|
||||||
return globalInstance.DefaultString(key, defaultVal)
|
return globalInstance.DefaultString(key, defaultVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get string slice
|
// DefaultStrings will get string slice
|
||||||
func DefaultStrings(key string, defaultVal []string) []string {
|
func DefaultStrings(key string, defaultVal []string) []string {
|
||||||
return globalInstance.DefaultStrings(key, defaultVal)
|
return globalInstance.DefaultStrings(key, defaultVal)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user