forked from leeprovoost/go-rest-api-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (43 loc) · 999 Bytes
/
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
package main
import (
"log"
"os"
"github.com/unrolled/render"
)
const local string = "LOCAL"
func main() {
var (
// environment variables
env = os.Getenv("ENV") // LOCAL, DEV, STG, PRD
port = os.Getenv("PORT") // server traffic on this port
version = os.Getenv("VERSION") // path to VERSION file
fixtures = os.Getenv("FIXTURES") // path to fixtures file
)
if env == "" || env == local {
// running from localhost, so set some default values
env = local
port = "3001"
version = "VERSION"
fixtures = "fixtures.json"
}
// reading version from file
version, err := ParseVersionFile(version)
if err != nil {
log.Fatal(err)
}
// load fixtures data into mock database
db, err := LoadFixturesIntoMockDatabase(fixtures)
if err != nil {
log.Fatal(err)
}
// initialse application context
ctx := AppContext{
Render: render.New(),
Version: version,
Env: env,
Port: port,
DB: db,
}
// start application
StartServer(ctx)
}