-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (47 loc) · 1.05 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
package main
import (
"encoding/json"
"log"
"os"
"path"
cli "github.com/helderfarias/dynamock/cli"
settings "github.com/codegangsta/cli"
)
var version string
func main() {
app := settings.NewApp()
app.Name = path.Base(os.Args[0])
app.Usage = "Dynamic Mock for Api Rest"
app.Version = version
app.Flags = []settings.Flag{
settings.StringFlag{
Name: "config, c",
Value: "config.json",
Usage: "-c config.json",
},
settings.StringFlag{
Name: "port, p",
Value: "3010",
Usage: "-p 3010",
},
}
app.Action = func(ctx *settings.Context) error {
configFile, err := os.Open(ctx.GlobalString("config"))
defer configFile.Close()
if err != nil {
log.Println("Opening config file: ", err.Error())
log.Println("Usage dynamock -h")
os.Exit(1)
}
config := cli.Configuration{}
jsonParser := json.NewDecoder(configFile)
if err = jsonParser.Decode(&config); err != nil {
log.Println("parsing config file", err.Error())
}
cli.Run(&config)
return nil
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}