Move route creation to independent function (#1362)
This commit is contained in:
@@ -191,7 +191,7 @@ func (api *API) GetSvcName(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, service.Name+"."+podNamespace)
|
||||
}
|
||||
|
||||
func (api *API) Serve(port int) {
|
||||
func (api *API) GetHandler() http.Handler {
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/healthz", api.HealthHandler).Methods("GET")
|
||||
// Give a useful error message if an older CLI attempts to make a request
|
||||
@@ -270,9 +270,12 @@ func (api *API) Serve(port int) {
|
||||
|
||||
r.Handle("/v2/apidocs.json", openAPI()).Methods("GET")
|
||||
|
||||
address := fmt.Sprintf(":%v", port)
|
||||
return r
|
||||
}
|
||||
|
||||
func (api *API) Serve(port int) {
|
||||
address := fmt.Sprintf(":%v", port)
|
||||
api.logger.Info("server started", zap.Int("port", port))
|
||||
err := http.ListenAndServe(address, r)
|
||||
err := http.ListenAndServe(address, api.GetHandler())
|
||||
api.logger.Fatal("done listening", zap.Error(err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user