-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
65 lines (55 loc) · 2.04 KB
/
Copy pathserver.go
File metadata and controls
65 lines (55 loc) · 2.04 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"log"
srvConfig "github.com/CHESSComputing/golib/config"
server "github.com/CHESSComputing/golib/server"
"github.com/CHESSComputing/golib/services"
"github.com/gin-gonic/gin"
)
// Verbose defines verbosity level
var Verbose int
// global variables
var _foxdenUser services.UserAttributes
// helper function to setup our router
func setupRouter(store *Store) *gin.Engine {
h := NewHandler(store)
routes := []server.Route{
{Method: "POST", Path: "", Handler: h.CreateCalibration, Authorized: true, Scope: "write"},
{Method: "GET", Path: "/label/*label", Handler: h.ListCalibrations, Authorized: false, Scope: "read"},
{Method: "GET", Path: "/valid/*label", Handler: h.GetValidCalibration, Authorized: true, Scope: "read"},
{Method: "GET", Path: "/history/*label", Handler: h.GetHistory, Authorized: true, Scope: "read"},
{Method: "PUT", Path: "/correct/*label", Handler: h.CorrectCalibration, Authorized: true, Scope: "write"},
{Method: "DELETE", Path: "/iov/:id", Handler: h.DeleteIOV, Authorized: true, Scope: "delete"},
{Method: "DELETE", Path: "/label/*label", Handler: h.DeleteByLabel, Authorized: true, Scope: "delete"},
}
r := server.Router(routes, nil, "static", srvConfig.Config.CalibrationData.WebServer)
return r
}
// Server defines our HTTP server
func Server() {
// init Verbose
Verbose = srvConfig.Config.CalibrationData.WebServer.Verbose
// make a choice of foxden user
switch srvConfig.Config.CalibrationData.FoxdenUser.User {
case "Maglab":
_foxdenUser = &services.MaglabUser{}
case "CHESS":
_foxdenUser = &services.CHESSUser{}
default:
_foxdenUser = &services.CHESSUser{}
}
_foxdenUser.Init()
dsn := srvConfig.Config.CalibrationData.DBUri
if dsn == "" {
log.Fatal("unable to get CalibrationData.DBUri foxden parameter")
}
store, err := NewStore(dsn)
if err != nil {
log.Fatalf("failed to connect to db: %v", err)
}
defer store.Close()
// setup web router and start the service
r := setupRouter(store)
webServer := srvConfig.Config.CalibrationData.WebServer
server.StartServer(r, webServer)
}