-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (57 loc) · 1.51 KB
/
main.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
package main
import (
"log"
"net/http"
"os"
"strings"
)
const (
LOCAL_ADDRESS = "localhost:8088"
REMOTE_ADDRESS = "localhost:8080"
TRACE_ENDPOINT = "https://trace-api.newrelic.com/trace/v1"
SERVICE_NAME = "Mock CDN"
)
func main() {
account := os.Getenv("NEW_RELIC_ACCOUNT")
if len(account) == 0 {
log.Printf("Please set env var NEW_RELIC_ACCOUNT")
os.Exit(0)
}
poa := os.Getenv("NEW_RELIC_POA")
if len(account) == 0 {
poa = account
}
licenseKey := os.Getenv("NEW_RELIC_LICENSE_KEY")
if len(licenseKey) == 0 {
log.Printf("Please set env var NEW_RELIC_LICENSE_KEY")
os.Exit(0)
}
traceEndpoint := os.Getenv("TRACE_ENDPOINT")
if len(traceEndpoint) == 0 {
traceEndpoint = TRACE_ENDPOINT
}
serviceName := os.Getenv("SERVICE_NAME")
if len(serviceName) == 0 {
serviceName = SERVICE_NAME
}
local := os.Getenv("LOCAL_ADDRESS")
if len(local) == 0 {
local = LOCAL_ADDRESS
}
remote := os.Getenv("REMOTE_ADDRESS")
if len(remote) == 0 {
remote = REMOTE_ADDRESS
}
var nrTracestateEnabled bool
nrTracestate := strings.ToLower(os.Getenv("NEW_RELIC_TRACESTATE"))
if nrTracestate == "1" || nrTracestate == "true" {
nrTracestateEnabled = true
}
// HTTP client for Trace API
traceClient := makeClient(licenseKey, traceEndpoint, poa, account, serviceName, nrTracestateEnabled)
// The / pattern matches everything
http.HandleFunc("/", makeHandleAll(remote, traceClient))
log.Printf("Remote Server at %s", remote)
log.Printf("Local Server at %s", local)
log.Fatal(http.ListenAndServe(local, nil))
}