-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (40 loc) · 1.37 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
// isolat project isolat.go
package main
import (
"flag"
"github.com/goarne/web"
"mesan.no/fagark/isolat/core"
"net/http"
"strconv"
)
func main() {
appConfig := lastAppKonfig()
core.InitLoggers(appConfig.Logging)
skrivOppstartsMelding(appConfig)
http.ListenAndServe(":"+strconv.FormatInt(appConfig.Server.Port, 10), opprettIsolatRessurs(appConfig))
}
//Logger applikasjonskonfigurasjon
func skrivOppstartsMelding(appConfig core.AppConfig) {
core.Info.Println("Laster appconfig:", appConfig.Logging.Filename)
core.Info.Println("Starter isolat på port:", strconv.FormatInt(appConfig.Server.Port, 10))
core.Info.Println("Isolat er tilgjengelig på ", appConfig.Server.Root)
core.Info.Println("Skriver til loggfil: ", appConfig.Logging.Filename)
}
//Laster inn applikasjonskonfigurasjon fra en JSON konfigurasjonsfil.
func lastAppKonfig() core.AppConfig {
configFile := flag.String("config", "./config/appconfig.json", "Fullt navn til applikasjonens konfigurasjonsfil (json)")
flag.Parse()
appConfig := core.AppConfig{}
appConfig.ReadConfig(*configFile)
return appConfig
}
//Oppretter REST ressurs for applikasjon
func opprettIsolatRessurs(appConfig core.AppConfig) *web.WebRouter {
r := web.NewRoute()
r.Path(appConfig.Server.Root)
r.Method(web.HttpGet).Method(web.HttpPost)
r.Handler(core.NyRestHandler())
router := web.NewWebRouter()
router.AddRoute(r)
return router
}