forked from SlashDB/timesheet-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargs.go
More file actions
50 lines (43 loc) · 1.44 KB
/
Copy pathargs.go
File metadata and controls
50 lines (43 loc) · 1.44 KB
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
package main
import (
"flag"
"fmt"
"log"
"strings"
)
// ParsedArgs - container for parsed CLI args.
type ParsedArgs struct {
Port uint
Interface,
Address,
SdbInstanceAddr,
SdbDBName,
SdbAPIKey,
SdbAPIValue,
RefIDPrefix string
EchoMode bool
}
// Parse - parses the command line arguments and populates the ParsedArgs object with the outcome
func Parse() *ParsedArgs {
pa := &ParsedArgs{}
flag.StringVar(&pa.Interface, "net-interface", "localhost", "network interface to serve on")
flag.UintVar(&pa.Port, "port", 8000, "local port to serve on")
flag.StringVar(&pa.SdbInstanceAddr, "sdb-address", "https://demo.slashdb.com", "SlashDB instance address")
flag.StringVar(&pa.SdbDBName, "sdb-dbname", "timesheet", "SlashDB DB name i.e. https://demo.slashdb.com/db/>>timesheet<<")
flag.StringVar(&pa.RefIDPrefix, "sdb-ref-id-prefix", "__href", "SlashDB's object ref URL prefix")
flag.BoolVar(&pa.EchoMode, "echo-mode", true, "printout SlashDB's connection info - usefull for debugging")
var sdbAPIKey string
flag.StringVar(
&sdbAPIKey,
"sdb-apikey", "apikey:timesheet-api-key", "SlashDB user API key, key and value separated by single ':'",
)
flag.Parse()
pa.Address = fmt.Sprintf("%s:%d", pa.Interface, pa.Port)
// extract SlashDB API key
if tmp := strings.Split(sdbAPIKey, ":"); len(tmp) != 2 {
log.Fatalln(fmt.Errorf("expected key, value pair, got: %s", sdbAPIKey))
} else {
pa.SdbAPIKey, pa.SdbAPIValue = tmp[0], tmp[1]
}
return pa
}