Documentation ¶
Overview ¶
Package g provides commonly used type/function defines and coupled calling for creating commonly used objects.
Index ¶
- func Cfg(name ...string) *gcfg.Config
- func Client() *gclient.Client
- func Config(name ...string) *gcfg.Config
- func DB(name ...string) gdb.DB
- func Dump(values ...interface{})
- func DumpJson(value any)
- func DumpTo(writer io.Writer, value interface{}, option gutil.DumpOption)
- func DumpWithOption(value interface{}, option gutil.DumpOption)
- func DumpWithType(values ...interface{})
- func Go(ctx context.Context, goroutineFunc func(ctx context.Context), ...)
- func I18n(name ...string) *gi18n.Manager
- func IsEmpty(value interface{}, traceSource ...bool) bool
- func IsNil(value interface{}, traceSource ...bool) bool
- func Listen()
- func Log(name ...string) *glog.Logger
- func Model(tableNameOrStruct ...interface{}) *gdb.Model
- func ModelRaw(rawSql string, args ...interface{}) *gdb.Model
- func Redis(name ...string) *gredis.Redis
- func RequestFromCtx(ctx context.Context) *ghttp.Request
- func Res(name ...string) *gres.Resource
- func Resource(name ...string) *gres.Resource
- func Server(name ...interface{}) *ghttp.Server
- func SetDebug(enabled bool)
- func TCPServer(name ...interface{}) *gtcp.Server
- func Throw(exception interface{})
- func Try(ctx context.Context, try func(ctx context.Context)) (err error)
- func TryCatch(ctx context.Context, try func(ctx context.Context), ...)
- func UDPServer(name ...interface{}) *gudp.Server
- func Validator() *gvalid.Validator
- func View(name ...string) *gview.View
- func Wait()
- type Array
- type ArrayAny
- type ArrayInt
- type ArrayStr
- type Ctx
- type List
- type ListAnyAny
- type ListAnyBool
- type ListAnyInt
- type ListAnyStr
- type ListIntAny
- type ListIntBool
- type ListIntInt
- type ListIntStr
- type ListStrAny
- type ListStrBool
- type ListStrInt
- type ListStrStr
- type Map
- type MapAnyAny
- type MapAnyBool
- type MapAnyInt
- type MapAnyStr
- type MapIntAny
- type MapIntBool
- type MapIntInt
- type MapIntStr
- type MapStrAny
- type MapStrBool
- type MapStrInt
- type MapStrStr
- type Meta
- type Slice
- type SliceAny
- type SliceInt
- type SliceStr
- type Var
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dump ¶
func Dump(values ...interface{})
Dump dumps a variable to stdout with more manually readable.
func DumpTo ¶
func DumpTo(writer io.Writer, value interface{}, option gutil.DumpOption)
DumpTo writes variables `values` as a string in to `writer` with more manually readable
func DumpWithOption ¶
func DumpWithOption(value interface{}, option gutil.DumpOption)
DumpWithOption returns variables `values` as a string with more manually readable.
func DumpWithType ¶
func DumpWithType(values ...interface{})
DumpWithType acts like Dump, but with type information. Also see Dump.
func Go ¶
func Go( ctx context.Context, goroutineFunc func(ctx context.Context), recoverFunc func(ctx context.Context, exception error), )
Go creates a new asynchronous goroutine function with specified recover function.
The parameter `recoverFunc` is called when any panic during executing of `goroutineFunc`. If `recoverFunc` is given nil, it ignores the panic from `goroutineFunc` and no panic will throw to parent goroutine.
But, note that, if `recoverFunc` also throws panic, such panic will be thrown to parent goroutine.
func I18n ¶
I18n returns an instance of gi18n.Manager. The parameter `name` is the name for the instance.
func IsEmpty ¶
IsEmpty checks whether given `value` empty. It returns true if `value` is in: 0, nil, false, "", len(slice/map/chan) == 0. Or else it returns true.
The parameter `traceSource` is used for tracing to the source variable if given `value` is type of pointer that also points to a pointer. It returns true if the source is empty when `traceSource` is true. Note that it might use reflect feature which affects performance a little.
func IsNil ¶
IsNil checks whether given `value` is nil. Parameter `traceSource` is used for tracing to the source variable if given `value` is type of pointer that also points to a pointer. It returns nil if the source is nil when `traceSource` is true. Note that it might use reflect feature which affects performance a little.
func Listen ¶
func Listen()
Listen is an alias of gproc.Listen, which handles the signals received and automatically calls registered signal handler functions. It blocks until shutdown signals received and all registered shutdown handlers done.
func Log ¶
Log returns an instance of glog.Logger. The parameter `name` is the name for the instance.
func RequestFromCtx ¶
RequestFromCtx retrieves and returns the Request object from context.
func Resource ¶
Resource returns an instance of Resource. The parameter `name` is the name for the instance.
func Server ¶
Server returns an instance of http server with specified name.
Example ¶
package main import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" ) func main() { // A hello world example. s := g.Server() s.BindHandler("/", func(r *ghttp.Request) { r.Response.Write("hello world") }) s.SetPort(8999) s.Run() }
Output:
func SetDebug ¶
func SetDebug(enabled bool)
SetDebug enables/disables the GoFrame internal logging manually. Note that this function is not concurrent safe, be aware of the DATA RACE, which means you should call this function in your boot but not the runtime.
func Throw ¶
func Throw(exception interface{})
Throw throws an exception, which can be caught by TryCatch function.
func Try ¶
Try implements try... logistics using internal panic...recover. It returns error if any exception occurs, or else it returns nil.
func TryCatch ¶
func TryCatch(ctx context.Context, try func(ctx context.Context), catch func(ctx context.Context, exception error))
TryCatch implements try...catch... logistics using internal panic...recover. It automatically calls function `catch` if any exception occurs and passes the exception as an error.
But, note that, if function `catch` also throws panic, the current goroutine will panic.
func Validator ¶
Validator is a convenience function, which creates and returns a new validation manager object.
Types ¶
type Array ¶
type Array = []interface{} // Array is alias of frequently-used slice type []interface{}.
type ArrayAny ¶
type ArrayAny = []interface{} // ArrayAny is alias of frequently-used slice type []interface{}.
type ArrayStr ¶
type ArrayStr = []string // ArrayStr is alias of frequently-used slice type []string.
type ListAnyAny ¶
type ListAnyAny = []MapAnyAny // ListAnyAny is alias of frequently-used slice type []MapAnyAny.
type ListAnyBool ¶
type ListAnyBool = []MapAnyBool // ListAnyBool is alias of frequently-used slice type []MapAnyBool.
type ListAnyInt ¶
type ListAnyInt = []MapAnyInt // ListAnyInt is alias of frequently-used slice type []MapAnyInt.
type ListAnyStr ¶
type ListAnyStr = []MapAnyStr // ListAnyStr is alias of frequently-used slice type []MapAnyStr.
type ListIntAny ¶
type ListIntAny = []MapIntAny // ListIntAny is alias of frequently-used slice type []MapIntAny.
type ListIntBool ¶
type ListIntBool = []MapIntBool // ListIntBool is alias of frequently-used slice type []MapIntBool.
type ListIntInt ¶
type ListIntInt = []MapIntInt // ListIntInt is alias of frequently-used slice type []MapIntInt.
type ListIntStr ¶
type ListIntStr = []MapIntStr // ListIntStr is alias of frequently-used slice type []MapIntStr.
type ListStrAny ¶
type ListStrAny = []MapStrAny // ListStrAny is alias of frequently-used slice type []MapStrAny.
type ListStrBool ¶
type ListStrBool = []MapStrBool // ListStrBool is alias of frequently-used slice type []MapStrBool.
type ListStrInt ¶
type ListStrInt = []MapStrInt // ListStrInt is alias of frequently-used slice type []MapStrInt.
type ListStrStr ¶
type ListStrStr = []MapStrStr // ListStrStr is alias of frequently-used slice type []MapStrStr.
type Map ¶
type Map = map[string]interface{} // Map is alias of frequently-used map type map[string]interface{}.
type MapAnyAny ¶
type MapAnyAny = map[interface{}]interface{} // MapAnyAny is alias of frequently-used map type map[interface{}]interface{}.
type MapAnyBool ¶
type MapAnyBool = map[interface{}]bool // MapAnyBool is alias of frequently-used map type map[interface{}]bool.
type MapAnyInt ¶
type MapAnyInt = map[interface{}]int // MapAnyInt is alias of frequently-used map type map[interface{}]int.
type MapAnyStr ¶
type MapAnyStr = map[interface{}]string // MapAnyStr is alias of frequently-used map type map[interface{}]string.
type MapIntAny ¶
type MapIntAny = map[int]interface{} // MapIntAny is alias of frequently-used map type map[int]interface{}.
type MapIntBool ¶
type MapStrAny ¶
type MapStrAny = map[string]interface{} // MapStrAny is alias of frequently-used map type map[string]interface{}.
type MapStrBool ¶
type Slice ¶
type Slice = []interface{} // Slice is alias of frequently-used slice type []interface{}.
type SliceAny ¶
type SliceAny = []interface{} // SliceAny is alias of frequently-used slice type []interface{}.