-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (75 loc) · 1.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"go.api/server"
"github.com/urfave/cli"
"fmt"
"os"
"io/ioutil"
"encoding/json"
"go.api/dblogic"
"errors"
)
var conf dblogic.Config
var (
PATH string = ""
VERSION string = "0.1"
)
var flags []cli.Flag = []cli.Flag {
cli.StringFlag{
Name: "config, c",
Usage: "Load configuration from `FILE`",
Destination: &PATH,
},
cli.StringFlag{
Name: "mghost",
Usage: "MongoDB Hostname to connect",
Destination: &conf.MongoDBhost,
},
cli.StringFlag{
Name: "mgname",
Usage: "MongoDB Name to connect",
Destination: &conf.MongoDBname,
},
cli.StringFlag{
Name: "mgdocname",
Usage: "MongoDB DocName to connect",
Destination: &conf.MongoDBdocname,
},
cli.StringFlag{
Name: "arsphost",
Usage: "Aerospike Hostname to connect",
Destination: &conf.AerospikeHost,
},
cli.StringFlag{
Name: "arspport",
Usage: "Aerospike Port number to connect",
Destination: &conf.AerospikePort,
},
}
func main(){
app := cli.NewApp()
app.Name = "test RESTful api"
app.Usage = "simple CRUD - mangoDB and aerospike as a cache"
app.Version = VERSION
app.Flags = flags
app.Action = runAPI
fmt.Println(app.Run(os.Args))
}
func ExtractConfig(path string, config *dblogic.Config) dblogic.Config{
file, _ := ioutil.ReadFile(path)
json.Unmarshal(file, &config)
return *config
}
func runAPI(*cli.Context) error {
if PATH != "" {
ExtractConfig(PATH, &conf)
}
if conf.MongoDBhost == "" {
return errors.New("Nothing found in MongoDB Hostname variable")
}
if conf.AerospikeHost == "" {
return errors.New("Nothing found in Aerospike Hostname variable")
}
server.Run(conf)
return nil
}