-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
58 lines (49 loc) · 1.69 KB
/
server.go
File metadata and controls
58 lines (49 loc) · 1.69 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
package main
// server module
//
// Copyright (c) 2025 - Valentin Kuznetsov <vkuznet@gmail.com>
//
import (
"log"
srvConfig "github.com/CHESSComputing/golib/config"
docdb "github.com/CHESSComputing/golib/docdb"
server "github.com/CHESSComputing/golib/server"
"github.com/CHESSComputing/golib/services"
"github.com/gin-gonic/gin"
)
// global variables
var _header, _footer string
var metaDB docdb.DocDB
var Verbose int
// in production code
var (
_httpReadRequest services.HTTPClient = services.NewHttpRequest("read", 0)
_httpWriteRequest services.HTTPClient = services.NewHttpRequest("write", 0)
)
// helper function to setup our router
func setupRouter() *gin.Engine {
routes := []server.Route{
{Method: "GET", Path: "/records", Handler: recordsHandler, Authorized: true, Scope: "read"},
{Method: "GET", Path: "/record/:uuid", Handler: getHandler, Authorized: true, Scope: "read"},
{Method: "PUT", Path: "/record/:uuid", Handler: putHandler, Authorized: true, Scope: "write"},
{Method: "POST", Path: "/record", Handler: postHandler, Authorized: true, Scope: "write"},
{Method: "DELETE", Path: "/record/:uuid", Handler: deleteHandler, Authorized: true, Scope: "delete"},
}
r := server.Router(routes, nil, "static", srvConfig.Config.Sync.WebServer)
return r
}
// Server defines our HTTP server
func Server() {
var err error
// init docdb
metaDB, err = docdb.InitializeDocDB(srvConfig.Config.Sync.MongoDB.DBUri)
if err != nil {
log.Fatal(err)
}
go syncDaemon(srvConfig.Config.Sync.SleepInterval)
// setup web router and start the service
r := setupRouter()
webServer := srvConfig.Config.Sync.WebServer
Verbose = srvConfig.Config.Sync.WebServer.Verbose
server.StartServer(r, webServer)
}