forked from cloudfoundry/cf-acceptance-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
36 lines (28 loc) · 709 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
package env
import (
"encoding/json"
"io"
"net/http"
"os"
"strings"
"github.com/gorilla/mux"
)
func NameHandler(res http.ResponseWriter, req *http.Request) {
io.WriteString(res, os.Getenv(mux.Vars(req)["name"]))
}
func JSONHandler(res http.ResponseWriter, req *http.Request) {
envMap := make(map[string]string)
for _, e := range os.Environ() {
kv := strings.Split(e, "=")
envMap[kv[0]] = kv[1]
}
envJSON, _ := json.Marshal(envMap)
res.Header().Add("Content-Type", "application/json")
res.Write(envJSON)
}
func InstanceGuidHandler(res http.ResponseWriter, req *http.Request) {
io.WriteString(res, InstanceGuid())
}
func InstanceGuid() string {
return os.Getenv("CF_INSTANCE_GUID")
}