/
rpc.go
39 lines (29 loc) · 1009 Bytes
/
rpc.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
38
39
package main
import (
"context"
"net/http"
"github.com/Filecoin-Titan/titan/api/types"
"github.com/Filecoin-Titan/titan/lib/rpcenc"
"github.com/Filecoin-Titan/titan/node/handler"
"github.com/Filecoin-Titan/titan/api"
"github.com/Filecoin-Titan/titan/metrics/proxy"
"github.com/filecoin-project/go-jsonrpc"
"github.com/gorilla/mux"
)
func CandidateHandler(verify func(ctx context.Context, token string) (*types.JWTPayload, error), a api.Candidate, permissioned bool) http.Handler {
mux := mux.NewRouter()
readerHandler, readerServerOpt := rpcenc.ReaderParamDecoder()
rpcServer := jsonrpc.NewServer(readerServerOpt)
wapi := proxy.MetricedCandidateAPI(a)
if permissioned {
wapi = api.PermissionedCandidateAPI(wapi)
}
rpcServer.Register("titan", wapi)
mux.Handle("/rpc/v0", rpcServer)
mux.Handle("/rpc/streams/v0/push/{uuid}", readerHandler)
mux.PathPrefix("/").Handler(http.DefaultServeMux) // pprof
if !permissioned {
return mux
}
return handler.New(verify, mux.ServeHTTP)
}