forked from rainycape/gondola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal.go
66 lines (55 loc) · 1.34 KB
/
internal.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package internal
import (
"fmt"
"os"
"path/filepath"
"strings"
"gnd.la/util/yaml"
)
// Constants set by gnd.la/cache/layer, read by gnd.la/app.Context
const (
LayerCachedKey = "___gondola_cached"
LayerServedFromCacheKey = "___gondola_layer_served_from_cache"
)
var (
inTest bool
goRun bool
inAppEngine bool
)
// InTest returns true iff called when running
// from go test.
func InTest() bool {
return inTest
}
// IsGoRun returns true iff called when running
// from go run.
func IsGoRun() bool {
return goRun
}
func InAppEngine() bool {
return inAppEngine
}
func InAppEngineDevServer() bool {
return os.Getenv("RUN_WITH_DEVAPPSERVER") != ""
}
func AppEngineAppId() string {
var m map[string]interface{}
if err := yaml.UnmarshalFile("app.yaml", &m); err == nil {
// XXX: your-app-id is the default in app.yaml in GAE templates, found
// in the gondolaweb repository. Keep these in sync.
if id, ok := m["application"].(string); ok && id != "your-app-id" {
return id
}
}
return ""
}
func AppEngineAppHost() string {
if id := AppEngineAppId(); id != "" {
return fmt.Sprintf("http://%s.appspot.com", id)
}
return ""
}
func init() {
inTest = strings.Contains(os.Args[0], string(filepath.Separator)+"_test"+string(filepath.Separator))
goRun = strings.Contains(os.Args[0], "_obj"+string(filepath.Separator)+"exe")
}