-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
52 lines (42 loc) · 1.12 KB
/
router.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
40
41
42
43
44
45
46
47
48
49
50
51
52
package service
import (
"fmt"
"net/http"
"sync/atomic"
"time"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
log "github.com/oleggorj/service-common-lib/common/logging"
)
var (
g_router = mux.NewRouter()
)
func RegisterHandlerFunction(path string, method string, f func(http.ResponseWriter, *http.Request)) {
g_router.Path(path).Methods(method).HandlerFunc(f)
}
func RegisterHandler(path string, method string, f http.Handler) {
g_router.Path(path).Methods(method).Handler(f)
}
// Endpoints router function
//@params
// Port number to bind
//@return
//
func Router(port string) *mux.Router {
isReady := &atomic.Value{}
isReady.Store(false)
go func() {
log.Info("Readyz probe is negative by default...")
time.Sleep(10 * time.Second)
isReady.Store(true)
log.Info("Readyz probe is positive.")
}()
g_router.HandleFunc("/readyz", readyz(isReady))
g_router.Path("/healthz").Methods("GET").HandlerFunc(healthz)
// TODO: implement metrics endpoint
g_router.Path("/metrics").Methods("GET").HandlerFunc(healthz)
n := negroni.Classic()
n.UseHandler(g_router)
n.Run(fmt.Sprintf(":%s", port))
return g_router
}