forked from instructure/straitjacket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
37 lines (31 loc) · 1 KB
/
server.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
package main
import (
"log"
"net/http"
"straitjacket/engine"
"straitjacket/handlers"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
negronilogrus "github.com/meatballhat/negroni-logrus"
"github.com/pilu/xrequestid"
"github.com/rs/cors"
)
func newServerStack(engine *engine.Engine) *negroni.Negroni {
context := handlers.NewContext(engine)
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", context.IndexHandler).Methods("GET")
router.HandleFunc("/execute", context.ExecuteHandler).Methods("POST")
router.HandleFunc("/info", context.InfoHandler).Methods("GET")
server := negroni.New(xrequestid.New(16),
context,
negronilogrus.NewCustomMiddleware(logrus.InfoLevel, &logrus.JSONFormatter{}, "straitjacket"),
cors.Default(),
negroni.NewStatic(http.Dir("public")))
server.UseHandler(router)
return server
}
func startServer(engine *engine.Engine, addr string) {
server := newServerStack(engine)
log.Fatal(http.ListenAndServe(addr, server))
}