diff --git a/.example/net/ghttp/server/log/log_error.go b/.example/net/ghttp/server/log/log_error.go index b6445afa2..6b8bc48a4 100644 --- a/.example/net/ghttp/server/log/log_error.go +++ b/.example/net/ghttp/server/log/log_error.go @@ -7,9 +7,7 @@ import ( func main() { s := ghttp.GetServer() s.BindHandler("/log/error", func(r *ghttp.Request) { - if j := r.GetJson(); j != nil { - r.Response.Write(j.Get("test")) - } + panic("OMG") }) s.SetErrorLogEnabled(true) s.SetPort(8199) diff --git a/.example/other/test.go b/.example/other/test.go index 08c55a582..b35f25f0f 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,13 +1,17 @@ package main import ( - "fmt" - "github.com/gogf/gf/text/gstr" + "github.com/gogf/gf/net/ghttp" ) func main() { - a := "aaaaa_post" - b := "aaaaa_" - c := gstr.TrimLeftStr(a, b) - fmt.Println(c) + s := ghttp.GetServer() + s.BindHandler("/log/path", func(r *ghttp.Request) { + r.Response.Writeln("请到/tmp/gf.log目录查看日志") + }) + s.SetLogPath("/tmp/gf.log") + s.SetAccessLogEnabled(true) + s.SetErrorLogEnabled(true) + s.SetPort(8199) + s.Run() } diff --git a/container/gtype/bool.go b/container/gtype/bool.go index 5307549ff..e090283e0 100644 --- a/container/gtype/bool.go +++ b/container/gtype/bool.go @@ -12,6 +12,7 @@ import ( "sync/atomic" ) +// Bool is a struct for concurrent-safe operation for type bool. type Bool struct { value int32 } @@ -21,7 +22,7 @@ var ( bytesFalse = []byte("false") ) -// NewBool returns a concurrent-safe object for bool type, +// NewBool creates and returns a concurrent-safe object for bool type, // with given initial value . func NewBool(value ...bool) *Bool { t := &Bool{} @@ -50,7 +51,7 @@ func (v *Bool) Set(value bool) (old bool) { return } -// Val atomically loads t.valueue. +// Val atomically loads and returns t.valueue. func (v *Bool) Val() bool { return atomic.LoadInt32(&v.value) > 0 } diff --git a/container/gtype/byte.go b/container/gtype/byte.go index 0ed17f5a6..02a5c36f9 100644 --- a/container/gtype/byte.go +++ b/container/gtype/byte.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Byte is a struct for concurrent-safe operation for type byte. type Byte struct { value int32 } -// NewByte returns a concurrent-safe object for byte type, +// NewByte creates and returns a concurrent-safe object for byte type, // with given initial value . func NewByte(value ...byte) *Byte { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Byte) Set(value byte) (old byte) { return byte(atomic.SwapInt32(&v.value, int32(value))) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Byte) Val() byte { return byte(atomic.LoadInt32(&v.value)) } diff --git a/container/gtype/bytes.go b/container/gtype/bytes.go index 639b57ffb..a6cc7f219 100644 --- a/container/gtype/bytes.go +++ b/container/gtype/bytes.go @@ -13,11 +13,12 @@ import ( "sync/atomic" ) +// Bytes is a struct for concurrent-safe operation for type []byte. type Bytes struct { value atomic.Value } -// NewBytes returns a concurrent-safe object for []byte type, +// NewBytes creates and returns a concurrent-safe object for []byte type, // with given initial value . func NewBytes(value ...[]byte) *Bytes { t := &Bytes{} @@ -40,7 +41,7 @@ func (v *Bytes) Set(value []byte) (old []byte) { return } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Bytes) Val() []byte { if s := v.value.Load(); s != nil { return s.([]byte) diff --git a/container/gtype/float32.go b/container/gtype/float32.go index b91667059..4334ac3b3 100644 --- a/container/gtype/float32.go +++ b/container/gtype/float32.go @@ -14,11 +14,12 @@ import ( "unsafe" ) +// Float32 is a struct for concurrent-safe operation for type float32. type Float32 struct { value uint32 } -// NewFloat32 returns a concurrent-safe object for float32 type, +// NewFloat32 creates and returns a concurrent-safe object for float32 type, // with given initial value . func NewFloat32(value ...float32) *Float32 { if len(value) > 0 { @@ -39,7 +40,7 @@ func (v *Float32) Set(value float32) (old float32) { return math.Float32frombits(atomic.SwapUint32(&v.value, math.Float32bits(value))) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Float32) Val() float32 { return math.Float32frombits(atomic.LoadUint32(&v.value)) } diff --git a/container/gtype/float64.go b/container/gtype/float64.go index 1e2ec954b..f3eaf9cdc 100644 --- a/container/gtype/float64.go +++ b/container/gtype/float64.go @@ -14,11 +14,12 @@ import ( "unsafe" ) +// Float64 is a struct for concurrent-safe operation for type float64. type Float64 struct { value uint64 } -// NewFloat64 returns a concurrent-safe object for float64 type, +// NewFloat64 creates and returns a concurrent-safe object for float64 type, // with given initial value . func NewFloat64(value ...float64) *Float64 { if len(value) > 0 { @@ -39,7 +40,7 @@ func (v *Float64) Set(value float64) (old float64) { return math.Float64frombits(atomic.SwapUint64(&v.value, math.Float64bits(value))) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Float64) Val() float64 { return math.Float64frombits(atomic.LoadUint64(&v.value)) } diff --git a/container/gtype/int.go b/container/gtype/int.go index 3349b464f..e5e6a4210 100644 --- a/container/gtype/int.go +++ b/container/gtype/int.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Int is a struct for concurrent-safe operation for type int. type Int struct { value int64 } -// NewInt returns a concurrent-safe object for int type, +// NewInt creates and returns a concurrent-safe object for int type, // with given initial value . func NewInt(value ...int) *Int { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Int) Set(value int) (old int) { return int(atomic.SwapInt64(&v.value, int64(value))) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Int) Val() int { return int(atomic.LoadInt64(&v.value)) } diff --git a/container/gtype/int32.go b/container/gtype/int32.go index 8ab6355cb..148c55030 100644 --- a/container/gtype/int32.go +++ b/container/gtype/int32.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Int32 is a struct for concurrent-safe operation for type int32. type Int32 struct { value int32 } -// NewInt32 returns a concurrent-safe object for int32 type, +// NewInt32 creates and returns a concurrent-safe object for int32 type, // with given initial value . func NewInt32(value ...int32) *Int32 { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Int32) Set(value int32) (old int32) { return atomic.SwapInt32(&v.value, value) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Int32) Val() int32 { return atomic.LoadInt32(&v.value) } diff --git a/container/gtype/int64.go b/container/gtype/int64.go index 43bf71175..678a7fdc5 100644 --- a/container/gtype/int64.go +++ b/container/gtype/int64.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Int64 is a struct for concurrent-safe operation for type int64. type Int64 struct { value int64 } -// NewInt64 returns a concurrent-safe object for int64 type, +// NewInt64 creates and returns a concurrent-safe object for int64 type, // with given initial value . func NewInt64(value ...int64) *Int64 { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Int64) Set(value int64) (old int64) { return atomic.SwapInt64(&v.value, value) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Int64) Val() int64 { return atomic.LoadInt64(&v.value) } diff --git a/container/gtype/interface.go b/container/gtype/interface.go index d986446c2..f6550df28 100644 --- a/container/gtype/interface.go +++ b/container/gtype/interface.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Interface is a struct for concurrent-safe operation for type interface{}. type Interface struct { value atomic.Value } -// NewInterface returns a concurrent-safe object for interface{} type, +// NewInterface creates and returns a concurrent-safe object for interface{} type, // with given initial value . func NewInterface(value ...interface{}) *Interface { t := &Interface{} @@ -39,7 +40,7 @@ func (v *Interface) Set(value interface{}) (old interface{}) { return } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Interface) Val() interface{} { return v.value.Load() } diff --git a/container/gtype/string.go b/container/gtype/string.go index 96880a568..3209ef6de 100644 --- a/container/gtype/string.go +++ b/container/gtype/string.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// String is a struct for concurrent-safe operation for type string. type String struct { value atomic.Value } -// NewString returns a concurrent-safe object for string type, +// NewString creates and returns a concurrent-safe object for string type, // with given initial value . func NewString(value ...string) *String { t := &String{} @@ -38,7 +39,7 @@ func (v *String) Set(value string) (old string) { return } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *String) Val() string { s := v.value.Load() if s != nil { diff --git a/container/gtype/uint.go b/container/gtype/uint.go index 10d7c2b73..2d9e29778 100644 --- a/container/gtype/uint.go +++ b/container/gtype/uint.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Uint is a struct for concurrent-safe operation for type uint. type Uint struct { value uint64 } -// NewUint returns a concurrent-safe object for uint type, +// NewUint creates and returns a concurrent-safe object for uint type, // with given initial value . func NewUint(value ...uint) *Uint { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Uint) Set(value uint) (old uint) { return uint(atomic.SwapUint64(&v.value, uint64(value))) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Uint) Val() uint { return uint(atomic.LoadUint64(&v.value)) } diff --git a/container/gtype/uint32.go b/container/gtype/uint32.go index 0f60da603..589557741 100644 --- a/container/gtype/uint32.go +++ b/container/gtype/uint32.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Uint32 is a struct for concurrent-safe operation for type uint32. type Uint32 struct { value uint32 } -// NewUint32 returns a concurrent-safe object for uint32 type, +// NewUint32 creates and returns a concurrent-safe object for uint32 type, // with given initial value . func NewUint32(value ...uint32) *Uint32 { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Uint32) Set(value uint32) (old uint32) { return atomic.SwapUint32(&v.value, value) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Uint32) Val() uint32 { return atomic.LoadUint32(&v.value) } diff --git a/container/gtype/uint64.go b/container/gtype/uint64.go index c89d539c6..8e9ddc83a 100644 --- a/container/gtype/uint64.go +++ b/container/gtype/uint64.go @@ -12,11 +12,12 @@ import ( "sync/atomic" ) +// Uint64 is a struct for concurrent-safe operation for type uint64. type Uint64 struct { value uint64 } -// NewUint64 returns a concurrent-safe object for uint64 type, +// NewUint64 creates and returns a concurrent-safe object for uint64 type, // with given initial value . func NewUint64(value ...uint64) *Uint64 { if len(value) > 0 { @@ -37,7 +38,7 @@ func (v *Uint64) Set(value uint64) (old uint64) { return atomic.SwapUint64(&v.value, value) } -// Val atomically loads t.value. +// Val atomically loads and returns t.value. func (v *Uint64) Val() uint64 { return atomic.LoadUint64(&v.value) }