-
Notifications
You must be signed in to change notification settings - Fork 328
/
env.go
36 lines (31 loc) · 1010 Bytes
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package env provides environment information for the golangorg server
// running on golang.org.
package env
import (
"log"
"os"
"strconv"
)
var requireDLSecretKey = boolEnv("GOLANGORG_REQUIRE_DL_SECRET_KEY")
// RequireDLSecretKey reports whether the download server secret key
// is expected to already exist, and the download server should panic
// on missing key instead of creating a new one.
func RequireDLSecretKey() bool {
return requireDLSecretKey
}
func boolEnv(key string) bool {
v := os.Getenv(key)
if v == "" {
// TODO(dmitshur): In the future, consider detecting if running in App Engine,
// and if so, making the environment variables mandatory rather than optional.
return false
}
b, err := strconv.ParseBool(v)
if err != nil {
log.Fatalf("environment variable %s (%q) must be a boolean", key, v)
}
return b
}