本文整理汇总了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
}