-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
37 lines (31 loc) · 936 Bytes
/
config.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
package main
import (
"flag"
"os"
"path/filepath"
)
type Config struct {
Addr string // :port or addr:port to listen on
CredentialsFile string // path to service-account.json file
}
func parseCommandLine() *Config {
// addr
dfltAddr := "localhost:8842"
addr := flag.String("addr", dfltAddr, "Address to listen on")
// credentialsFile defaults to env var, then relative path, then filename
dfltCredentialsFile := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
if dfltCredentialsFile == "" {
exe, err := os.Executable()
if err != nil {
dfltCredentialsFile = "service-account.json"
} else {
dfltCredentialsFile = filepath.Join(filepath.Dir(exe), "service-account.json")
}
}
credentialsFile := flag.String("credentialsFile", dfltCredentialsFile, "Path to service account credentials in JSON format")
flag.Parse()
return &Config{
Addr: *addr,
CredentialsFile: *credentialsFile,
}
}