-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathmain.go
46 lines (38 loc) · 1.21 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
//go:generate go-bindata-assetfs -ignore=node_modules -prefix "ui/src/client/" -pkg $GOPACKAGE ui/src/client/public/...
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
config := loadConfig()
app := defaultApplication(config.logger, config.httpTimeout)
if config.realURL != "" {
err := app.CheckCompatibility(config.configPath, config.realURL)
if err != nil {
log.Fatal(err)
}
} else {
svr, err := app.CreateServer(config.configPath, config.monkeyConfigPath, config.debugMode, getUIServer())
if err != nil {
log.Fatal(err)
} else {
config.logger.Printf("Listening on port %d", config.port)
config.logger.Printf("Admin on http://localhost:%d/mj-admin (only works on Chrome, sorry!)", config.port)
err = http.ListenAndServe(fmt.Sprintf(":%d", config.port), svr)
if err != nil {
msg := fmt.Sprintf("There was a problem starting the mockingjay server on port %d: %s", config.port, err.Error())
config.logger.Fatal(msg)
}
}
}
}
func getUIServer() http.Handler {
if os.Getenv("ENV") == "LOCAL" {
log.Println("Detected local dev mode, serving files from /ui")
return http.FileServer(http.Dir("./ui/src/client/public"))
}
return http.FileServer(assetFS())
}