-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
89 lines (62 loc) · 1.4 KB
/
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
)
type ConfigJson struct {
ClientSecretsFile string `json:"client_secrets_file"`
WinscpFlags string `json:"winscp_flags"`
}
// Global Flags
type FlagsStruct struct {
Adc bool
Auth bool
Login string
Info bool
}
type Config struct {
// Global debug flag
Debug bool
UseAdcCredentials bool
ProjectId string
ClientSecretsFile string
// Command to execute
Command int
// Command "exec"
RemoteCommand string
// Commands "download" and "upload"
SrcFile string
DstFile string
// Command line global options
Flags FlagsStruct
// Commands "benchmark download" and "benchark upload"
benchmark_size int64
// Command line winscp options
WinscpFlags []string
}
var config Config
func init_config() error {
in, err := os.Open("config.json")
if err != nil {
fmt.Println(err)
return err
}
defer in.Close()
data, err := ioutil.ReadAll(in)
var configJson ConfigJson
err = json.Unmarshal(data, &configJson)
if err != nil {
fmt.Println("Error: Cannot unmarshal JSON: ", err)
return err
}
config.ClientSecretsFile = configJson.ClientSecretsFile
// fmt.Println("Client Secrets File:", config.ClientSecretsFile)
if configJson.WinscpFlags != "" {
config.WinscpFlags = append([]string{"/rawsettings"}, strings.Fields(configJson.WinscpFlags)...)
}
process_cmdline()
return nil
}