Mathew Medoff před 5 roky
rodič
revize
9ef68afea6
1 změnil soubory, kde provedl 7 přidání a 4 odebrání
  1. 7 4
      api.go

+ 7 - 4
api.go

@@ -2,6 +2,7 @@ package api
 
 import (
 	"context"
+	"fmt"
 	"net/http"
 	"os"
 	"os/signal"
@@ -10,11 +11,12 @@ import (
 	"time"
 
 	"github.com/Sirupsen/logrus"
+	"github.com/gorilla/mux"
 )
 
 type Api struct {
 	httpServer *http.Server
-	mux        *http.ServeMux
+	mux        *mux.Router
 	online     bool
 	running    chan os.Signal
 }
@@ -29,15 +31,16 @@ func NewApi(serverAddress string) *Api {
 
 	webserver := &Api{
 		httpServer: srv,
-		mux:        http.NewServeMux(),
+		mux:        mux.NewRouter(),
 		online:     false,
 	}
 
 	return webserver
 }
 
-func (api *Api) AddHandler(path string, handler func(http.ResponseWriter, *http.Request)) {
-	api.mux.HandleFunc(path, handler)
+func (api *Api) AddHandler(path string, handler func(http.ResponseWriter, *http.Request), method string) {
+	fmt.Println(path)
+	api.mux.HandleFunc(path, handler).Methods(method)
 }
 
 func (api *Api) Start(wg *sync.WaitGroup) error {