本文整理汇总了Golang中os.Getenv函数的典型用法代码示例。如果您正苦于以下问题:Golang Getenv函数的具体用法?Golang Getenv怎么用?Golang Getenv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Getenv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewDaemon
// NewDaemon returns a Daemon instance to be used for testing.
// This will create a directory such as d123456789 in the folder specified by $DEST.
// The daemon will not automatically start.
func NewDaemon(c *check.C) *Daemon {
dest := os.Getenv("DEST")
c.Assert(dest, check.Not(check.Equals), "", check.Commentf("Please set the DEST environment variable"))
id := fmt.Sprintf("d%d", time.Now().UnixNano()%100000000)
dir := filepath.Join(dest, id)
daemonFolder, err := filepath.Abs(dir)
c.Assert(err, check.IsNil, check.Commentf("Could not make %q an absolute path", dir))
daemonRoot := filepath.Join(daemonFolder, "root")
c.Assert(os.MkdirAll(daemonRoot, 0755), check.IsNil, check.Commentf("Could not create daemon root %q", dir))
userlandProxy := true
if env := os.Getenv("DOCKER_USERLANDPROXY"); env != "" {
if val, err := strconv.ParseBool(env); err != nil {
userlandProxy = val
}
}
return &Daemon{
Command: "daemon",
id: id,
c: c,
folder: daemonFolder,
root: daemonRoot,
storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"),
userlandProxy: userlandProxy,
}
}
示例2: CreateTestFeature
// CreateTestFeature creates a random feature to be used during testing.
func CreateTestFeature(t *testing.T) *models.Feature {
s, err := store.NewMySQLStore(
os.Getenv("LAIKA_MYSQL_USERNAME"),
os.Getenv("LAIKA_MYSQL_PASSWORD"),
os.Getenv("LAIKA_MYSQL_HOST"),
os.Getenv("LAIKA_MYSQL_PORT"),
os.Getenv("LAIKA_MYSQL_DBNAME"),
)
require.NoError(t, err)
env, err := s.GetEnvironmentByName("test")
if err != nil {
env = &models.Environment{
Name: "test",
}
err = s.CreateEnvironment(env)
require.NoError(t, err)
}
feature := &models.Feature{
Name: "test_feature" + store.Token(),
Status: map[string]bool{
"test": true,
},
}
err = s.CreateFeature(feature)
require.NoError(t, err)
return feature
}
示例3: resolveConfiguration
func resolveConfiguration() (*configuration.Configuration, error) {
var configurationPath string
if flag.NArg() > 0 {
configurationPath = flag.Arg(0)
} else if os.Getenv("REGISTRY_CONFIGURATION_PATH") != "" {
configurationPath = os.Getenv("REGISTRY_CONFIGURATION_PATH")
}
if configurationPath == "" {
return nil, fmt.Errorf("configuration path unspecified")
}
fp, err := os.Open(configurationPath)
if err != nil {
return nil, err
}
config, err := configuration.Parse(fp)
if err != nil {
return nil, fmt.Errorf("error parsing %s: %v", configurationPath, err)
}
return config, nil
}
示例4: initDefaultCachePath
func initDefaultCachePath() string {
xdgCache := os.Getenv("XDG_CACHE_HOME")
if xdgCache == "" {
xdgCache = filepath.Join(os.Getenv("HOME"), ".cache")
}
return filepath.Join(xdgCache, "bashbrew")
}
示例5: TestBackend_configConnection
func TestBackend_configConnection(t *testing.T) {
b := Backend()
d1 := map[string]interface{}{
"value": os.Getenv("MYSQL_DSN"),
}
d2 := map[string]interface{}{
"connection_url": os.Getenv("MYSQL_DSN"),
}
d3 := map[string]interface{}{
"value": os.Getenv("MYSQL_DSN"),
"connection_url": os.Getenv("MYSQL_DSN"),
}
d4 := map[string]interface{}{}
logicaltest.Test(t, logicaltest.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Backend: b,
Steps: []logicaltest.TestStep{
testAccStepConfig(t, d1, false),
testAccStepConfig(t, d2, false),
testAccStepConfig(t, d3, false),
testAccStepConfig(t, d4, true),
},
})
}
示例6: main
func main() {
jenkins_address := os.Getenv("JENKINS_URL")
listen_address := os.Getenv("LISTEN_ADDRESS")
if listen_address == "" {
listen_address = "[::]:8080"
}
if jenkins_address == "" {
log.Fatalln("Use environment variables JENKINS_URL and LISTEN_ADDRESS (default \"[::]:8080\")")
}
remote, err := url.Parse(jenkins_address)
if err != nil {
log.Panic(err)
}
proxy := httputil.NewSingleHostReverseProxy(remote)
http.HandleFunc("/", handler(proxy))
log.Println("jenkins-authentication-proxy", version, "starting")
log.Println("Authentication endpoint:", planio_url)
err = http.ListenAndServe(listen_address, nil)
if err != nil {
log.Panic(err)
}
}
示例7: createPlaybackClient
func createPlaybackClient(t *testing.T) (c *Client) {
c = &Client{
ConsumerKey: os.Getenv("RDIO_API_KEY"),
ConsumerSecret: os.Getenv("RDIO_API_SECRET"),
Token: os.Getenv("RDIO_API_TOKEN"),
TokenSecret: os.Getenv("RDIO_API_TOKEN_SECRET"),
}
if c.ConsumerKey == "" {
t.Error("Rdio api key is missing (should be in the RDIO_API_KEY environment variable)")
}
if c.ConsumerSecret == "" {
t.Error("Rdio api secret is missing (should be in the RDIO_API_SECRET environment variable)")
}
if c.Token == "" {
t.Error("Rdio api user token is missing (should be in the RDIO_API_TOKEN environment variable)")
}
if c.TokenSecret == "" {
t.Error("Rdio api user secret is missing (should be in the RDIO_API_TOKEN_SECRET environment variable)")
}
return c
}
示例8: LookPath
func LookPath(file string) (string, os.Error) {
exts := []string{}
if x := os.Getenv(`PATHEXT`); x != `` {
exts = strings.Split(strings.ToLower(x), `;`, -1)
for i, e := range exts {
if e == `` || e[0] != '.' {
exts[i] = `.` + e
}
}
}
if strings.Contains(file, `\`) || strings.Contains(file, `/`) {
if f, ok := canExec(file, exts); ok {
return f, nil
}
return ``, &PathError{file}
}
if pathenv := os.Getenv(`PATH`); pathenv == `` {
if f, ok := canExec(`.\`+file, exts); ok {
return f, nil
}
} else {
for _, dir := range strings.Split(pathenv, `;`, -1) {
if f, ok := canExec(dir+`\`+file, exts); ok {
return f, nil
}
}
}
return ``, &PathError{file}
}
示例9: init
func init() {
// read database shit from flatfile here
// yes, currently this all just goes into an in-memory struct ... I
// want to move to a 'real database' if this ever becomes serious.
defaultPort, err := strconv.Atoi(os.Getenv("whatciv_port"))
if err != nil {
defaultPort = 80
}
// no checking done because blank is completely okay as a default here
defaultHost := os.Getenv("whatciv_host")
defaultDatabase := os.Getenv("whatciv_db")
if len(defaultDatabase) == 0 {
cwd, err := os.Getwd()
if err != nil {
panic("things went really, really wrong.")
}
defaultDatabase = fmt.Sprintf("%s/%s", cwd, "data.json")
}
flag.IntVarP(&config.Port, "port", "p", defaultPort, "Port to listen on for the web server")
flag.StringVarP(&config.Host, "host", "H", defaultHost, "Host to listen on for the web server")
flag.StringVarP(&config.Database, "db", "d", defaultDatabase, "JSON database of civs and strats to load")
flag.Parse()
config.HostAndPort = fmt.Sprintf("%s:%d", config.Host, config.Port)
}
示例10: NewClient
// NewClient returns a new client
func NewClient(config *Config) (*Client, error) {
// bootstrap the config
defConfig := DefaultConfig()
switch {
case len(config.Address) != 0:
case len(os.Getenv("CONSUL_HTTP_ADDR")) > 0:
config.Address = os.Getenv("CONSUL_HTTP_ADDR")
default:
config.Address = defConfig.Address
}
if len(config.Scheme) == 0 {
config.Scheme = defConfig.Scheme
}
if config.HttpClient == nil {
config.HttpClient = defConfig.HttpClient
}
if strings.HasPrefix(config.Address, "unix://") {
shortStr := strings.TrimPrefix(config.Address, "unix://")
t := &http.Transport{}
t.Dial = func(_, _ string) (net.Conn, error) {
return net.Dial("unix", shortStr)
}
config.HttpClient.Transport = t
config.Address = shortStr
}
client := &Client{
config: *config,
}
return client, nil
}
示例11: TestAccVcdSNAT_Basic
func TestAccVcdSNAT_Basic(t *testing.T) {
if v := os.Getenv("VCD_EXTERNAL_IP"); v == "" {
t.Skip("Environment variable VCD_EXTERNAL_IP must be set to run SNAT tests")
return
}
var e govcd.EdgeGateway
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVcdSNATDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(testAccCheckVcdSnat_basic, os.Getenv("VCD_EDGE_GATWEWAY"), os.Getenv("VCD_EXTERNAL_IP")),
Check: resource.ComposeTestCheckFunc(
testAccCheckVcdSNATExists("vcd_snat.bar", &e),
resource.TestCheckResourceAttr(
"vcd_snat.bar", "external_ip", os.Getenv("VCD_EXTERNAL_IP")),
resource.TestCheckResourceAttr(
"vcd_snat.bar", "internal_ip", "10.10.102.0/24"),
),
},
},
})
}
示例12: slackNotify
func slackNotify() {
accessToken := os.Getenv(slackEnv)
if accessToken == "" {
log.Fatalf("Missing access token, %s must be set", slackEnv)
}
vals := make(url.Values)
vals.Set("token", accessToken)
vals.Set("text", fmt.Sprintf("%s\n%s", *title, *message))
vals.Set("username", "noti")
if ch := os.Getenv(slackChannelEnv); ch == "" {
vals.Set("channel", "#random")
} else {
vals.Set("channel", ch)
}
resp, err := http.PostForm("https://slack.com/api/chat.postMessage", vals)
if err != nil {
log.Fatal(err)
}
r := make(map[string]interface{})
if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
resp.Body.Close()
log.Fatal(err)
}
resp.Body.Close()
if r["ok"] == false {
log.Fatal("Slack API error: ", r["error"])
}
}
示例13: TestLockInChild
func TestLockInChild(t *testing.T) {
f := os.Getenv("TEST_LOCK_FILE")
if f == "" {
// not child
return
}
lock := Lock
if v, _ := strconv.ParseBool(os.Getenv("TEST_LOCK_PORTABLE")); v {
lock = lockPortable
}
var lk io.Closer
for scan := bufio.NewScanner(os.Stdin); scan.Scan(); {
var err error
switch scan.Text() {
case "lock":
lk, err = lock(f)
case "unlock":
err = lk.Close()
lk = nil
case "exit":
// Simulate a crash, or at least not unlocking the lock.
os.Exit(0)
default:
err = fmt.Errorf("unexpected child command %q", scan.Text())
}
if err != nil {
fmt.Println(err)
} else {
fmt.Println("")
}
}
}
示例14: getProxyEnv
// The uppercase and the lowercase are available for the proxy settings.
// See the Go specification for details on these variables. https://golang.org/pkg/net/http/
func getProxyEnv(key string) string {
proxyValue := os.Getenv(strings.ToUpper(key))
if proxyValue == "" {
return os.Getenv(strings.ToLower(key))
}
return proxyValue
}
示例15: testAccPreCheck
func testAccPreCheck(t *testing.T) {
sf := os.Getenv("PUBLISH_SETTINGS_FILE")
if sf != "" {
publishSettings, err := ioutil.ReadFile(sf)
if err != nil {
t.Fatalf("Error reading AZURE_SETTINGS_FILE path: %s", err)
}
os.Setenv("AZURE_PUBLISH_SETTINGS", string(publishSettings))
}
if v := os.Getenv("AZURE_PUBLISH_SETTINGS"); v == "" {
subscriptionID := os.Getenv("AZURE_SUBSCRIPTION_ID")
certificate := os.Getenv("AZURE_CERTIFICATE")
if subscriptionID == "" || certificate == "" {
t.Fatal("either AZURE_PUBLISH_SETTINGS, PUBLISH_SETTINGS_FILE, or AZURE_SUBSCRIPTION_ID " +
"and AZURE_CERTIFICATE must be set for acceptance tests")
}
}
if v := os.Getenv("AZURE_STORAGE"); v == "" {
t.Fatal("AZURE_STORAGE must be set for acceptance tests")
}
}