gf/frame/g/g_func.go

73 lines
2.3 KiB
Go
Raw Normal View History

2021-01-17 21:46:25 +08:00
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
2018-09-26 09:58:49 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2018-09-26 09:58:49 +08:00
package g
import (
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/container/gvar"
"github.com/gogf/gf/internal/empty"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/gproc"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/util/gutil"
2018-09-26 09:58:49 +08:00
)
// NewVar returns a gvar.Var.
func NewVar(i interface{}, safe ...bool) *Var {
return gvar.New(i, safe...)
}
// Wait blocks until:
// 1. All the web servers shutdown, it does nothing if there's no running web server.
// 2. Shutdown signals received and all registered shutdown handlers done.
2018-09-26 09:58:49 +08:00
func Wait() {
2019-06-19 09:06:52 +08:00
ghttp.Wait()
gproc.Listen()
2018-09-26 09:58:49 +08:00
}
2019-02-27 22:17:09 +08:00
// Dump dumps a variable to stdout with more manually readable.
2019-06-19 09:06:52 +08:00
func Dump(i ...interface{}) {
gutil.Dump(i...)
2018-09-26 09:58:49 +08:00
}
2019-03-21 18:21:53 +08:00
// Export exports a variable to string with more manually readable.
2019-06-19 09:06:52 +08:00
func Export(i ...interface{}) string {
return gutil.Export(i...)
2019-03-21 18:21:53 +08:00
}
// Throw throws a exception, which can be caught by TryCatch function.
2019-02-27 22:17:09 +08:00
// It always be used in TryCatch function.
func Throw(exception interface{}) {
2019-06-19 09:06:52 +08:00
gutil.Throw(exception)
}
// Try implements try... logistics using internal panic...recover.
// It returns error if any exception occurs, or else it returns nil.
func Try(try func()) (err error) {
return gutil.Try(try)
}
// TryCatch implements try...catch... logistics using internal panic...recover.
// It automatically calls function <catch> if any exception occurs ans passes the exception as an error.
func TryCatch(try func(), catch ...func(exception error)) {
2019-06-19 09:06:52 +08:00
gutil.TryCatch(try, catch...)
}
2020-02-23 20:25:55 +08:00
// IsNil checks whether given <value> is nil.
// Parameter <traceSource> is used for tracing to the source variable if given <value> is type
// of a pinter that also points to a pointer. It returns nil if the source is nil when <traceSource>
// is true.
2020-02-23 20:25:55 +08:00
// Note that it might use reflect feature which affects performance a little bit.
func IsNil(value interface{}, traceSource ...bool) bool {
return empty.IsNil(value, traceSource...)
2020-02-23 20:25:55 +08:00
}
// 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.
func IsEmpty(value interface{}) bool {
2019-06-19 09:06:52 +08:00
return empty.IsEmpty(value)
}