Reworking in module definition

This commit is contained in:
Héctor Hurtado
2019-10-08 12:02:46 +02:00
parent 73e05afee3
commit fe7d962581
3 changed files with 25 additions and 19 deletions
+21 -17
View File
@@ -1,35 +1,39 @@
package control
import (
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/BBVA/kapow/internal/server/user"
)
type ControlServer struct {
bindAddr string
ctrlMux *mux.Router
func Run(bindAddr string) {
r := mux.NewRouter()
r.HandleFunc("/routes/{id}", removeRoute).
Methods("DELETE")
r.HandleFunc("/routes", listRoutes).
Methods("GET")
r.HandleFunc("/routes", addRoute).
Methods("POST")
log.Fatal(http.ListenAndServe(bindAddr, r))
}
var Server *ControlServer
func (srv *ControlServer) Run(bindAddr string) {
Server = &ControlServer{bindAddr, mux.NewRouter()}
Server.ctrlMux.HandleFunc("/routes/{id}", Server.removeRoute).Methods("DELETE")
Server.ctrlMux.HandleFunc("/routes", Server.listRoutes).Methods("GET")
Server.ctrlMux.HandleFunc("/routes", Server.addRoute).Methods("POST")
}
func (srv *ControlServer) removeRoute(http.ResponseWriter, *http.Request) {
func removeRoute(http.ResponseWriter, *http.Request) {
}
func (srv *ControlServer) listRoutes(http.ResponseWriter, *http.Request) {
func listRoutes(http.ResponseWriter, *http.Request) {
user.Routes.Snapshot()
}
func (srv *ControlServer) addRoute(http.ResponseWriter, *http.Request) {
func addRoute(http.ResponseWriter, *http.Request) {
user.Routes.Append(routeSpec)
}
+1 -1
View File
@@ -4,6 +4,6 @@ import (
"testing"
)
func TestNewControlServerFillsTheStructCorrectly(t *testing.T) {
func Test(t *testing.T) {
}