-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
41 lines (33 loc) · 930 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
package main
import (
"flag"
"fmt"
"github.com/OpenTreeMap/otm-ecoservice/ecorest"
"github.com/OpenTreeMap/otm-ecoservice/ecorest/config"
"github.com/ungerik/go-rest"
"log"
"os"
"runtime/pprof"
)
var (
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
)
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
cfg := config.LoadConfig()
endpoints := ecorest.GetManager(cfg)
rest.HandleGET("/itree_codes.json", endpoints.ITreeCodesGET)
rest.HandleGET("/eco.json", endpoints.EcoGET)
rest.HandlePOST("/eco_summary.json", endpoints.EcoSummaryPOST)
rest.HandlePOST("/eco_scenario.json", endpoints.EcoScenarioPOST)
rest.HandleGET("/invalidate_cache", endpoints.InvalidateCacheGET)
rest.RunServer(fmt.Sprintf("%v:%v", cfg.ServerHost, cfg.ServerPort), nil)
}