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:
Regan Yue 2022-07-08 21:19:52 +08:00 committed by GitHub
parent 2c506f7c2b
commit 49be2581d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 55 deletions

View File

@ -47,23 +47,23 @@ import (
// c.Incr("counter") // now is 2
// count := c.Get("counter").(int)
type Cache interface {
// get cached value by key.
// Get will get cached value by key.
Get(key string) interface{}
// GetMulti is a batch version of Get.
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
// delete cached value by key.
// Delete will delete cached value by key.
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
// decrease cached int value by key, as a counter.
// Decr will decrease cached int value by key, as a counter.
Decr(key string) error
// check if cached value exists or not.
// IsExist can check if cached value exists or not.
IsExist(key string) bool
// clear all cache.
// ClearAll will clear all cache.
ClearAll() error
// start gc routine based on config string settings.
// StartAndGC will start gc routine based on config string settings.
StartAndGC(config string) error
}

View File

@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// used to keep compatible with v1.x
// Package adapter used to keep compatible with v1.x
package adapter

View File

@ -158,7 +158,7 @@ func (bl *BeeLogger) EnableFuncCallDepth(b bool) {
(*logs.BeeLogger)(bl).EnableFuncCallDepth(b)
}
// set prefix
// SetPrefix will set prefix
func (bl *BeeLogger) SetPrefix(s string) {
(*logs.BeeLogger)(bl).SetPrefix(s)
}

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build go1.8
// +build go1.8
// Package orm provide ORM for MySQL/PostgreSQL/sqlite
@ -92,7 +93,7 @@ type ormer struct {
var _ Ormer = new(ormer)
// read data to model
// Read read data to model
func (o *ormer) Read(md interface{}, cols ...string) error {
if o.isTx {
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...)
}
// 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 {
if o.isTx {
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...)
}
// 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) {
if o.isTx {
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...)
}
// insert model data to database
// Insert will insert model data to database
func (o *ormer) Insert(md interface{}) (int64, error) {
if o.isTx {
return o.txDelegate.Insert(md)
@ -124,7 +125,7 @@ func (o *ormer) Insert(md interface{}) (int64, error) {
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) {
if o.isTx {
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...)
}
// update model to database.
// Update will update model to database.
// cols set the columns those want to update.
func (o *ormer) Update(md interface{}, cols ...string) (int64, error) {
if o.isTx {
@ -149,7 +150,7 @@ func (o *ormer) Update(md interface{}, cols ...string) (int64, error) {
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
func (o *ormer) Delete(md interface{}, cols ...string) (int64, error) {
if o.isTx {
@ -158,7 +159,7 @@ func (o *ormer) Delete(md interface{}, cols ...string) (int64, error) {
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 {
if o.isTx {
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)
}
// load related models to md model.
// LoadRelated load related models to md model.
// args are limit, offset int and order string.
//
// example:
@ -200,7 +201,7 @@ func (o *ormer) LoadRelated(md interface{}, name string, args ...interface{}) (i
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.
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
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)
}
// 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 {
if o.isTx {
return ErrTxHasBegan
@ -219,7 +220,7 @@ func (o *ormer) Using(name string) error {
return nil
}
// begin transaction
// Begin will begin transaction
func (o *ormer) Begin() error {
if o.isTx {
return ErrTxHasBegan
@ -240,7 +241,7 @@ func (o *ormer) BeginTx(ctx context.Context, opts *sql.TxOptions) error {
return nil
}
// commit transaction
// Commit will commit transaction
func (o *ormer) Commit() error {
if !o.isTx {
return ErrTxDone
@ -255,7 +256,7 @@ func (o *ormer) Commit() error {
return err
}
// rollback transaction
// Rollback will rollback transaction
func (o *ormer) Rollback() error {
if !o.isTx {
return ErrTxDone
@ -270,7 +271,7 @@ func (o *ormer) Rollback() error {
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 {
if o.isTx {
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 current using database Driver
// Driver return current using database Driver
func (o *ormer) Driver() Driver {
if o.isTx {
return o.txDelegate.Driver()
@ -286,7 +287,7 @@ func (o *ormer) Driver() Driver {
return o.delegate.Driver()
}
// return sql.DBStats for current database
// DBStats return sql.DBStats for current database
func (o *ormer) DBStats() *sql.DBStats {
if o.isTx {
return o.txDelegate.DBStats()

View File

@ -23,7 +23,7 @@ import (
// Log implement the log.Logger
type Log orm.Log
// costomer log func
// LogFunc is costomer log func
var LogFunc = orm.LogFunc
// NewLog set io.Writer to create a Logger.

View File

@ -35,7 +35,7 @@ type Fielder orm.Fielder
// Ormer define the orm interface
type Ormer interface {
// read data to model
// Read read data to model
// for example:
// this will find User by Id field
// u = &User{Id: user.Id}
@ -44,25 +44,25 @@ type Ormer interface {
// u = &User{UserName: "astaxie", Password: "pass"}
// err = Ormer.Read(u, "UserName")
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.
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)
// insert model data to database
// Insert will insert model data to database
// for example:
// user := new(User)
// id, err = Ormer.Insert(user)
// user must be a pointer and Insert will set user's pk field
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")
// postgres: InsertOrUpdate(model,"conflictColumnName") or InsertOrUpdate(model,"conflictColumnName","colu=colu+value")
// if colu type is integer : can use(+-*/), string : colu || "value"
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)
// update model to database.
// Update update model to database.
// 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
// for example:
@ -72,9 +72,9 @@ type Ormer interface {
// user.Extra.Data = "orm"
// num, err = Ormer.Update(&user, "Langs", "Extra")
Update(md interface{}, cols ...string) (int64, error)
// delete model in database
// Delete delete model in database
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.
//
// example:
@ -87,25 +87,25 @@ type Ormer interface {
// args[3] string order for example : "-Id"
// make sure the relation is defined in model struct tags.
LoadRelated(md interface{}, name string, args ...interface{}) (int64, error)
// create a models to models queryer
// QueryM2M create a models to models queryer
// for example:
// post := Post{Id: 4}
// m2m := Ormer.QueryM2M(&post, "Tags")
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.
// e.g. QueryTable("user"), QueryTable(&user{}) or QueryTable((*User)(nil)),
QueryTable(ptrStructOrTableName interface{}) QuerySeter
// switch to another registered database driver by given name.
Using(name string) error
// begin transaction
// Begin begin transaction
// for example:
// o := NewOrm()
// err := o.Begin()
// ...
// err = o.Rollback()
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.
// 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.
@ -116,11 +116,11 @@ type Ormer interface {
// ...
// err = o.Rollback()
BeginTx(ctx context.Context, opts *sql.TxOptions) error
// commit transaction
// Commit commit transaction
Commit() error
// rollback transaction
// Rollback rollback transaction
Rollback() error
// return a raw query seter for raw sql string.
// Raw return a raw query seter for raw sql string.
// for example:
// ormer.Raw("UPDATE `user` SET `user_name` = ? WHERE `user_name` = ?", "slene", "testing").Exec()
// // update user testing's name to slene

View File

@ -246,7 +246,7 @@ func camelString(s string) 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) {
if i >= 0 && i < len(a) {
r = a[i]
@ -258,7 +258,7 @@ func (a argString) Get(i int, args ...string) (r string) {
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) {
if i >= 0 && i < len(a) {
r = a[i]
@ -269,13 +269,13 @@ func (a argInt) Get(i int, args ...int) (r int) {
return
}
// parse time to string with location
// timeParse parse time to string with location
func timeParse(dateString, format string) (time.Time, error) {
tp, err := time.ParseInLocation(format, dateString, DefaultTimeLoc)
return tp, err
}
// get pointer indirect type
// indirectType get pointer indirect type
func indirectType(v reflect.Type) reflect.Type {
switch v.Kind() {
case reflect.Ptr:

View File

@ -144,7 +144,7 @@ func avg(items []time.Duration) time.Duration {
return time.Duration(int64(sum) / int64(len(items)))
}
// format bytes number friendly
// toH format bytes number friendly
func toH(bytes uint64) string {
switch {
case bytes < 1024:

View File

@ -7,7 +7,7 @@ import (
"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
func Mock(v interface{}) (err error) {
pv := reflect.ValueOf(v)

View File

@ -28,17 +28,17 @@ func InitGlobalInstance(name string, cfg string) error {
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 {
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) {
return globalInstance.String(key)
}
// get string slice
// Strings will get string slice
func Strings(key string) ([]string, error) {
return globalInstance.Strings(key)
}
@ -59,12 +59,12 @@ func Float(key string) (float64, error) {
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 {
return globalInstance.DefaultString(key, defaultVal)
}
// get string slice
// DefaultStrings will get string slice
func DefaultStrings(key string, defaultVal []string) []string {
return globalInstance.DefaultStrings(key, defaultVal)
}