代码拉取完成,页面将自动刷新
// Package gbuild manages the build-in variables from "gf build".
package gbuild
import (
"gitee.com/micro-tools/wf"
"gitee.com/micro-tools/wf/container/gvar"
"gitee.com/micro-tools/wf/encoding/gbase64"
"gitee.com/micro-tools/wf/internal/intlog"
"gitee.com/micro-tools/wf/internal/json"
"gitee.com/micro-tools/wf/util/gconv"
"runtime"
)
var (
builtInVarStr = "" // Raw variable base64 string.
builtInVarMap = map[string]interface{}{} // Binary custom variable map decoded.
)
func init() {
if builtInVarStr != "" {
err := json.UnmarshalUseNumber(gbase64.MustDecodeString(builtInVarStr), &builtInVarMap)
if err != nil {
intlog.Error(err)
}
builtInVarMap["gfVersion"] = wf.VERSION
builtInVarMap["goVersion"] = runtime.Version()
intlog.Printf("build variables: %+v", builtInVarMap)
} else {
intlog.Print("no build variables")
}
}
// Info returns the basic built information of the binary as map.
// Note that it should be used with gf-cli tool "gf build",
// which injects necessary information into the binary.
func Info() map[string]string {
return map[string]string{
"gf": GetString("gfVersion"),
"go": GetString("goVersion"),
"git": GetString("builtGit"),
"time": GetString("builtTime"),
}
}
// Get retrieves and returns the build-in binary variable with given name.
func Get(name string, def ...interface{}) interface{} {
if v, ok := builtInVarMap[name]; ok {
return v
}
if len(def) > 0 {
return def[0]
}
return nil
}
// GetVar retrieves and returns the build-in binary variable of given name as gvar.Var.
func GetVar(name string, def ...interface{}) *gvar.Var {
return gvar.New(Get(name, def...))
}
// GetString retrieves and returns the build-in binary variable of given name as string.
func GetString(name string, def ...interface{}) string {
return gconv.String(Get(name, def...))
}
// Map returns the custom build-in variable map.
func Map() map[string]interface{} {
return builtInVarMap
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。