Commit b46e57f0 authored by Muhammad Umair Zafar's avatar Muhammad Umair Zafar
Browse files

add new handler for /api and /user-api endpoints and also add MetricsHandler...

add new handler for /api and /user-api endpoints and also add MetricsHandler function for the metrics as per the development guide
parent 0cfa1797
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -7,13 +7,16 @@
 * Contact: cti_support@etsi.org
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package swagger
package server

import (
	"fmt"
	"net/http"
	"strings"

	httpLog "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-http-logger"
	met "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-metrics"

	"github.com/gorilla/mux"
)

@@ -27,12 +30,13 @@ type Route struct {
type Routes []Route

func NewRouter() *mux.Router {
	var handler http.Handler
	router := mux.NewRouter().StrictSlash(true)
	for _, route := range routes {
		var handler http.Handler
		handler = route.HandlerFunc
		handler = Logger(handler, route.Name)

		handler = met.MetricsHandler(handler, sandboxName, serviceName)
		handler = httpLog.LogRx(handler)
		router.
			Methods(route.Method).
			Path(route.Pattern).
@@ -40,6 +44,20 @@ func NewRouter() *mux.Router {
			Handler(handler)
	}
	
	// Path prefix router order is important
	// Service Api files
	handler = http.StripPrefix("/sandbox-api/v2/api/", http.FileServer(http.Dir("./api/")))
	router.
		PathPrefix("/sandbox-api/v2/api/").
		Name("Api").
		Handler(handler)
	// User supplied service API files
	handler = http.StripPrefix("/sandbox-api/v2/user-api/", http.FileServer(http.Dir("./user-api/")))
	router.
		PathPrefix("/sandbox-api/v2/user-api/").
		Name("UserApi").
		Handler(handler)

	return router
}