1 Star 0 Fork 0

micro-tools / wf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gbuild.go 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
545403892 提交于 2023-09-27 22:16 . 升级go-ole
// 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
}
Go
1
https://gitee.com/micro-tools/wf.git
git@gitee.com:micro-tools/wf.git
micro-tools
wf
wf
v1.0.2

搜索帮助