-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
68 lines (57 loc) · 1.36 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
65
66
67
68
package main
import (
"fmt"
"os"
"strconv"
"github.com/brandonto/rest-api-microservice-demo/core"
"github.com/brandonto/rest-api-microservice-demo/db"
)
const defaultDbBucketName = "DetailedMessageBucket"
const defaultPort = uint64(55555)
func main() {
// Outputs usage if number of arguments are off
//
if len(os.Args) > 4 || len(os.Args) < 2 {
fmt.Println("usage: " + os.Args[0] + " db_path [port] [db_bucket_name]")
return
}
// First argument is the filepath of the database
//
dbFile := os.Args[1]
// Second (optional) argument is the the port number
//
port := defaultPort
if len(os.Args) > 2 {
// Some sanity check for the port argument before using
//
var err error
port, err = strconv.ParseUint(os.Args[2], 10, 64)
if err != nil {
fmt.Println("port argument must be an unsigned integer")
return
}
if port < uint64(49152) || port > uint64(65535) {
fmt.Println("port argument must be a value between 49152–65535")
return
}
}
// Third (optional) argument is the the bucket name
//
dbBucketName := defaultDbBucketName
if len(os.Args) > 3 {
dbBucketName = os.Args[3]
}
// Configure and run the application
//
dbCfg := db.Config{
FilePath: dbFile,
BucketName: dbBucketName,
}
coreCfg := core.Config{
DbCfg: dbCfg,
Port: port,
EnableLogger: true,
Standalone: true,
}
core.Run(coreCfg)
}