-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
29 lines (21 loc) · 1007 Bytes
/
routes.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
package main
import (
"net/http"
"github.com/justinas/alice"
)
// The routes() method returns a servemux containing our application routes.
func (calc *calculator) routes() http.Handler {
mux := http.NewServeMux()
//------------------ Register the Static Files -----------------------
fileServer := http.FileServer(http.Dir("./static/"))
mux.Handle("GET /static/", http.StripPrefix("/static", fileServer))
mux.HandleFunc("GET /{$}", calc.home)
mux.HandleFunc("POST /create-stream", calc.authMiddleware(calc.createStream)) //curl -X POST http://localhost:9000/create-stream -H "Authorization: Bearer <your-jwt-token>"
mux.HandleFunc("POST /contribute/aggregate/{id}", calc.contributeAggregate)
mux.HandleFunc("GET /snapshot/aggregate/{id}", calc.returnAggregate)
mux.HandleFunc("GET /public-key/{id}", calc.getPublicKey)
// Create a middleware chain
standard := alice.New(calc.logRequest)
// Return the 'standard' middleware chain followed by the servemux.
return standard.Then(mux)
}