forked from bp-alex/ibconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
43 lines (34 loc) · 1.06 KB
/
handler.go
File metadata and controls
43 lines (34 loc) · 1.06 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
package server
import (
"database/sql"
"log"
"net/http"
"os"
"github.com/ant0ine/go-json-rest/rest"
"github.com/benalexau/ibconnect/core"
)
// Handler returns an initialised Handler.
func Handler(errInfo bool, db *sql.DB, n *core.Notifier) http.Handler {
u := &Util{
ErrInfo: errInfo,
}
accountHandler := AccountHandler{u: u, db: db, n: n}
null, _ := os.Open(os.DevNull)
handler := rest.ResourceHandler{
EnableGzip: true,
EnableRelaxedContentType: true,
DisableJsonIndent: false,
EnableStatusService: false,
EnableResponseStackTrace: false,
EnableLogAsJson: true,
Logger: log.New(null, "", 0),
}
var routes []*rest.Route
routes = append(routes, &rest.Route{"GET", "/v1/accounts", accountHandler.GetAll})
routes = append(routes, &rest.Route{"GET", "/v1/accounts/:accountCode", accountHandler.GetLatest})
routes = append(routes, &rest.Route{"GET", "/v1/accounts/:accountCode/*timestamp", accountHandler.GetReport})
handler.SetRoutes(routes...)
var h http.Handler
h = &handler
return h
}