-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (39 loc) · 1.05 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
package main
import (
"encoding/json"
"os"
"log"
"fmt"
"github.com/emicklei/go-restful"
"net/http"
)
func main() {
configuration := readConfiguration()
go fetchNewData(configuration)
go hashSessions(configuration)
wsContainer := restful.NewContainer()
s := SessionResource{}
s.RegisterTo(wsContainer)
l := LogResource{}
l.RegisterTo(wsContainer)
cors := restful.CrossOriginResourceSharing{
ExposeHeaders: []string{"X-My-Header"},
AllowedHeaders: []string{"Content-Type"},
CookiesAllowed: false,
Container: wsContainer}
wsContainer.Filter(cors.Filter)
wsContainer.Filter(wsContainer.OPTIONSFilter)
log.Printf("Start listening on localhost:" + configuration.Port)
server := &http.Server{Addr: ":" + configuration.Port, Handler: wsContainer}
log.Fatal(server.ListenAndServe())
}
func readConfiguration() (Configuration) {
file, _ := os.Open("conf.json")
decoder := json.NewDecoder(file)
configuration := Configuration{}
err := decoder.Decode(&configuration)
if err != nil {
fmt.Println("error:", err)
}
return configuration
}