From 7c234e04374abf85d560601b0cc0a11ebde19b94 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 15 Jun 2019 22:06:47 +0800 Subject: [PATCH] golint for gvar --- g/container/gvar/gvar.go | 189 +++++++++++++++++++++++++++------------ g/os/gview/gview.go | 6 +- 2 files changed, 135 insertions(+), 60 deletions(-) diff --git a/g/container/gvar/gvar.go b/g/container/gvar/gvar.go index 728fe2570..05b3098e8 100644 --- a/g/container/gvar/gvar.go +++ b/g/container/gvar/gvar.go @@ -8,104 +8,179 @@ package gvar import ( - "github.com/gogf/gf/g/container/gtype" - "github.com/gogf/gf/g/os/gtime" - "github.com/gogf/gf/g/util/gconv" - "time" + "github.com/gogf/gf/g/container/gtype" + "github.com/gogf/gf/g/os/gtime" + "github.com/gogf/gf/g/util/gconv" + "time" ) +// Var is an universal variable type. type Var struct { - value interface{} // Underlying value. - safe bool // Concurrent safe or not. + value interface{} // Underlying value. + safe bool // Concurrent safe or not. } // New returns a new Var with given . // The parameter used to specify whether using Var in un-concurrent-safety, // which is false in default, means concurrent-safe. -func New(value interface{}, unsafe...bool) *Var { - v := &Var{} - if len(unsafe) == 0 || !unsafe[0] { - v.safe = true - v.value = gtype.NewInterface(value) - } else { - v.value = value - } - return v +func New(value interface{}, unsafe ...bool) *Var { + v := &Var{} + if len(unsafe) == 0 || !unsafe[0] { + v.safe = true + v.value = gtype.NewInterface(value) + } else { + v.value = value + } + return v } // Set sets to , and returns the old value. func (v *Var) Set(value interface{}) (old interface{}) { - if v.safe { - old = v.value.(*gtype.Interface).Set(value) - } else { - old = v.value - v.value = value - } - return + if v.safe { + old = v.value.(*gtype.Interface).Set(value) + } else { + old = v.value + v.value = value + } + return } // Val returns the current value of . func (v *Var) Val() interface{} { - if v.safe { - return v.value.(*gtype.Interface).Val() - } else { - return v.value - } + if v.safe { + return v.value.(*gtype.Interface).Val() + } + return v.value } -// See Val(). +// Interface is alias of Val. func (v *Var) Interface() interface{} { - return v.Val() + return v.Val() } // Time converts and returns as time.Time. // The parameter specifies the format of the time string using gtime, // eg: Y-m-d H:i:s. -func (v *Var) Time(format...string) time.Time { - return gconv.Time(v.Val(), format...) +func (v *Var) Time(format ...string) time.Time { + return gconv.Time(v.Val(), format...) } -// TimeDuration converts and returns as time.Duration. +// Duration converts and returns as time.Duration. // If value of is string, then it uses time.ParseDuration for conversion. func (v *Var) Duration() time.Duration { - return gconv.Duration(v.Val()) + return gconv.Duration(v.Val()) } // GTime converts and returns as *gtime.Time. // The parameter specifies the format of the time string using gtime, // eg: Y-m-d H:i:s. -func (v *Var) GTime(format...string) *gtime.Time { - return gconv.GTime(v.Val(), format...) +func (v *Var) GTime(format ...string) *gtime.Time { + return gconv.GTime(v.Val(), format...) } // Struct maps value of to . // The parameter should be a pointer to a struct instance. // The parameter is used to specify the key-to-attribute mapping rules. -func (v *Var) Struct(pointer interface{}, mapping...map[string]string) error { - return gconv.Struct(v.Val(), pointer, mapping...) +func (v *Var) Struct(pointer interface{}, mapping ...map[string]string) error { + return gconv.Struct(v.Val(), pointer, mapping...) } -func (v *Var) IsNil() bool { return v.Val() == nil } -func (v *Var) Bytes() []byte { return gconv.Bytes(v.Val()) } -func (v *Var) String() string { return gconv.String(v.Val()) } -func (v *Var) Bool() bool { return gconv.Bool(v.Val()) } +// IsNil checks whether is nil. +func (v *Var) IsNil() bool { + return v.Val() == nil +} -func (v *Var) Int() int { return gconv.Int(v.Val()) } -func (v *Var) Int8() int8 { return gconv.Int8(v.Val()) } -func (v *Var) Int16() int16 { return gconv.Int16(v.Val()) } -func (v *Var) Int32() int32 { return gconv.Int32(v.Val()) } -func (v *Var) Int64() int64 { return gconv.Int64(v.Val()) } +// Bytes converts and returns as []byte. +func (v *Var) Bytes() []byte { + return gconv.Bytes(v.Val()) +} -func (v *Var) Uint() uint { return gconv.Uint(v.Val()) } -func (v *Var) Uint8() uint8 { return gconv.Uint8(v.Val()) } -func (v *Var) Uint16() uint16 { return gconv.Uint16(v.Val()) } -func (v *Var) Uint32() uint32 { return gconv.Uint32(v.Val()) } -func (v *Var) Uint64() uint64 { return gconv.Uint64(v.Val()) } +// String converts and returns as string. +func (v *Var) String() string { + return gconv.String(v.Val()) +} -func (v *Var) Float32() float32 { return gconv.Float32(v.Val()) } -func (v *Var) Float64() float64 { return gconv.Float64(v.Val()) } +// Bool converts and returns as bool. +func (v *Var) Bool() bool { + return gconv.Bool(v.Val()) +} -func (v *Var) Ints() []int { return gconv.Ints(v.Val()) } -func (v *Var) Floats() []float64 { return gconv.Floats(v.Val()) } -func (v *Var) Strings() []string { return gconv.Strings(v.Val()) } -func (v *Var) Interfaces() []interface{} { return gconv.Interfaces(v.Val()) } +// Int converts and returns as int. +func (v *Var) Int() int { + return gconv.Int(v.Val()) +} + +// Int8 converts and returns as int8. +func (v *Var) Int8() int8 { + return gconv.Int8(v.Val()) +} + +// Int16 converts and returns as int16. +func (v *Var) Int16() int16 { + return gconv.Int16(v.Val()) +} + +// Int32 converts and returns as int32. +func (v *Var) Int32() int32 { + return gconv.Int32(v.Val()) +} + +// Int64 converts and returns as int64. +func (v *Var) Int64() int64 { + return gconv.Int64(v.Val()) +} + +// Uint converts and returns as uint. +func (v *Var) Uint() uint { + return gconv.Uint(v.Val()) +} + +// Uint8 converts and returns as uint8. +func (v *Var) Uint8() uint8 { + return gconv.Uint8(v.Val()) +} + +// Uint16 converts and returns as uint16. +func (v *Var) Uint16() uint16 { + return gconv.Uint16(v.Val()) +} + +// Uint32 converts and returns as uint32. +func (v *Var) Uint32() uint32 { + return gconv.Uint32(v.Val()) +} + +// Uint64 converts and returns as uint64. +func (v *Var) Uint64() uint64 { + return gconv.Uint64(v.Val()) +} + +// Float32 converts and returns as float32. +func (v *Var) Float32() float32 { + return gconv.Float32(v.Val()) +} + +// Float64 converts and returns as float64. +func (v *Var) Float64() float64 { + return gconv.Float64(v.Val()) +} + +// Ints converts and returns as []int. +func (v *Var) Ints() []int { + return gconv.Ints(v.Val()) +} + +// Floats converts and returns as []float64. +func (v *Var) Floats() []float64 { + return gconv.Floats(v.Val()) +} + +// Strings converts and returns as []string. +func (v *Var) Strings() []string { + return gconv.Strings(v.Val()) +} + +// Interfaces converts and returns as []interfaces{}. +func (v *Var) Interfaces() []interface{} { + return gconv.Interfaces(v.Val()) +} diff --git a/g/os/gview/gview.go b/g/os/gview/gview.go index bc690967d..edd96d213 100644 --- a/g/os/gview/gview.go +++ b/g/os/gview/gview.go @@ -20,6 +20,7 @@ import ( "sync" ) +// View object for template engine. type View struct { mu sync.RWMutex paths *garray.StringArray // Searching path array. @@ -28,10 +29,10 @@ type View struct { delimiters []string // Customized template delimiters. } -// Template params type. +// Params is type for template params. type Params = map[string]interface{} -// Customized template function map type. +// FuncMap is type for custom template functions. type FuncMap = map[string]interface{} // Default view object. @@ -218,7 +219,6 @@ func (view *View) AddPath(path string) error { return nil } view.paths.Append(realPath) - //glog.Debug("[gview] AddPath:", realPath) return nil }