forked from KurokuLabs/margo
/
cry.go
44 lines (39 loc) · 1.2 KB
/
cry.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
// Why, Go[d], Why?
// Why would you make Yotsuba cry
package why_would_you_make_yotsuba_cry
import (
"go/build"
"os"
"reflect"
)
var (
// AgentBuildContext holds info about the environment in which the margo agent was built.
// It's a drop-in replacement for build.Default which is set to the user's own GOPATH, etc.
AgentBuildContext = func() *build.Context {
bctx := build.Default
if gp := os.Getenv("MARGO_AGENT_GOPATH"); gp != "" {
bctx.GOPATH = gp
}
return &bctx
}()
// AgentBuildEnv holds environment variables used when building the margo agent.
// It contains environment variables like GOPATH and GO111MODULE which may be
// different from the user's environment but essential for building the agent.
AgentBuildEnv = map[string]string{
"GOPATH": AgentBuildContext.GOPATH,
"GO111MODULE": os.Getenv("MARGO_AGENT_GO111MODULE"),
}
)
// IsNil *probably* takes care of this BS: https://golang.org/doc/faq#nil_error
func IsNil(v interface{}) bool {
if v == nil {
return true
}
// But wait... there's more!
x := reflect.ValueOf(v)
switch x.Kind() {
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Slice:
return x.IsNil()
}
return false
}