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