本文整理匯總了Golang中v/io/x/lib/envvar.Vars.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vars.Get方法的具體用法?Golang Vars.Get怎麽用?Golang Vars.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類v/io/x/lib/envvar.Vars
的用法示例。
在下文中一共展示了Vars.Get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setSyncbaseEnv
// setSyncbaseEnv adds the LevelDB third-party C++ libraries Vanadium
// Go code depends on to the CGO_CFLAGS and CGO_LDFLAGS variables.
func setSyncbaseEnv(ctx *tool.Context, env *envvar.Vars, root string) error {
libs := []string{
"leveldb",
"snappy",
}
// TODO(rogulenko): get these vars from a config file.
goos, goarch := env.Get("GOOS"), env.Get("GOARCH")
if goos == "" {
goos = runtime.GOOS
}
if goarch == "" {
goarch = runtime.GOARCH
}
for _, lib := range libs {
cflags := env.GetTokens("CGO_CFLAGS", " ")
cxxflags := env.GetTokens("CGO_CXXFLAGS", " ")
ldflags := env.GetTokens("CGO_LDFLAGS", " ")
dir, err := ThirdPartyCCodePath(goos, goarch)
if err != nil {
return err
}
dir = filepath.Join(dir, lib)
if _, err := ctx.Run().Stat(dir); err != nil {
if !os.IsNotExist(err) {
return err
}
continue
}
cflags = append(cflags, filepath.Join("-I"+dir, "include"))
cxxflags = append(cxxflags, filepath.Join("-I"+dir, "include"))
ldflags = append(ldflags, filepath.Join("-L"+dir, "lib"))
if runtime.GOARCH == "linux" {
ldflags = append(ldflags, "-Wl,-rpath", filepath.Join(dir, "lib"))
}
env.SetTokens("CGO_CFLAGS", cflags, " ")
env.SetTokens("CGO_CXXFLAGS", cxxflags, " ")
env.SetTokens("CGO_LDFLAGS", ldflags, " ")
}
return nil
}