forked from MixinNetwork/supergroup.mixin.one
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
30 lines (26 loc) · 1.04 KB
/
http.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
package main
import (
"fmt"
"net/http"
"github.com/MixinNetwork/supergroup.mixin.one/config"
"github.com/MixinNetwork/supergroup.mixin.one/durable"
"github.com/MixinNetwork/supergroup.mixin.one/middlewares"
"github.com/MixinNetwork/supergroup.mixin.one/routes"
"github.com/dimfeld/httptreemux"
"github.com/facebookgo/grace/gracehttp"
"github.com/gorilla/handlers"
"github.com/unrolled/render"
)
func StartServer(database *durable.Database) error {
logger := durable.NewLoggerClient()
router := httptreemux.New()
routes.RegisterHanders(router)
routes.RegisterRoutes(router)
handler := middlewares.Authenticate(router)
handler = middlewares.Constraint(handler)
handler = middlewares.Context(handler, database, render.New(render.Options{UnEscapeHTML: true}))
handler = middlewares.Stats(handler, "http", true, config.BuildVersion)
handler = middlewares.Log(handler, logger, "http")
handler = handlers.ProxyHeaders(handler)
return gracehttp.Serve(&http.Server{Addr: fmt.Sprintf(":%d", config.AppConfig.Service.HTTPListenPort), Handler: handler})
}