-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (48 loc) · 1.33 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
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
)
func readEnvFile(fileName string) {
config := make(map[string]interface{})
//filename is the path to the json config file
file, err := os.Open(fileName)
if err != nil {
log.Fatalf("Error - unable to open file: %s\n", err)
}
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
log.Fatalf("Error - unable to decode JSON: %s\n", err)
}
for k, v := range config {
// os.Setenv("uri", config["uri"])
// os.Setenv(k, v)
os.Setenv(k, fmt.Sprintf("%v", v))
}
}
func main() {
fmt.Println()
// read config file at env.json
readEnvFile("env.json")
//decide what to do.
flag.Parse()
args := flag.Args()
// handle no args
if len(args) == 0 {
fmt.Println("You need to submit a command. See 'help' command")
} else if args[0] == "help" {
fmt.Printf("The default config file is env.json and auth/token is saved to token.json. Commands: \nauth - launches oauth2 authentication server on http://localhost:3000\nget - command used to get information from server. type 'get help' for more info.\nsubmit - 'submit fileName.json' see example json file\n\n")
} else if args[0] == "auth" {
auth()
} else if args[0] == "get" {
get(args)
} else if args[0] == "submit" {
submit(args)
} else {
fmt.Println("Command not recognized")
}
}