-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (52 loc) · 1.41 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
package main
import (
"flag"
)
const (
defaultHost = "localhost"
defaultPort = 9000
defaultMockPath = "test"
defaultConfigFile = ""
defaultApplication = "app"
defaultWatch = false
NotFoundResponseFile = "404.json"
CORSFile = "cors.json"
)
var (
host *string
port *int
mockPath *string
app *string
configFilePath *string
watch *bool
)
// Config for running the Mock server
// it will contain configs for multiple app
type Config struct {
Apps map[string]App
}
var (
Conf Config
appMockPath string
Mock MockConfig
)
func init() {
host = flag.String("host", defaultHost, "if you run your server on a different host")
port = flag.Int("port", defaultPort, "port to run the server")
watch = flag.Bool("watch", defaultWatch, "if true, then watch for any change in app mock config and reload")
mockPath = flag.String("mock", defaultMockPath, "directory where your mock configs are saved")
app = flag.String("app", defaultApplication, "name of the app which has to be mocked")
configFilePath = flag.String("config", defaultConfigFile, "path with configuration file")
flag.Parse()
appMockPath = *mockPath + "/" + *app
LoadConfig(*configFilePath, *host, *port)
LoadMockConfig(appMockPath)
}
func main() {
if *watch {
initializeWatcher(appMockPath)
}
NewServer(Conf.Apps, *app, Mock).
AttachHandlers().
Run()
}