Commit 128bf770 authored by Stefan Dähling's avatar Stefan Dähling
Browse files

use gorilla mux (wip)

parent 8629239b
Pipeline #411634 passed with stages
in 7 minutes and 8 seconds
......@@ -14,6 +14,7 @@ require (
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/google/uuid v1.1.0 // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gorilla/mux v1.8.0
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f // indirect
github.com/json-iterator/go v1.1.5 // indirect
github.com/kr/pretty v0.1.0 // indirect
......
......@@ -90,7 +90,11 @@ func StartAMS() (err error) {
}
ams.stor.setCloneMAPInfo(cmap)
// start to listen and serve requests
err = ams.listen()
serv := ams.server(9000)
if err != nil {
return
}
err = ams.listen(serv)
return
}
......
......@@ -84,18 +84,23 @@ func TestAMS(t *testing.T) {
}
ams.stor.setCloneMAPInfo(cmap)
// start to listen and serve requests
mux := http.NewServeMux()
mux.HandleFunc("/api/", ams.handleAPI)
s := &http.Server{
Addr: ":10001",
Handler: mux,
}
serv := ams.server(10001)
// r := mux.NewRouter()
// r.PathPrefix("/api/").HandlerFunc(ams.handleAPI)
// mux := http.NewServeMux()
// mux.HandleFunc("/api/", ams.handleAPI)
// serv := &http.Server{
// Addr: ":10001",
// Handler: r,
// }
// start dummy client
go dummyClient(s, t)
go dummyClient(serv, t)
// start ams server
err = s.ListenAndServe()
err = serv.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
t.Error(err)
}
......
......@@ -56,6 +56,7 @@ import (
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/common/httpreply"
"git.rwth-aachen.de/acs/public/cloud/mas/clonemap/pkg/schemas"
"github.com/gorilla/mux"
)
// handleAPI is the global handler for requests to path /api
......@@ -427,15 +428,25 @@ func (ams *AMS) handleAgencyID(masID int, imID int, agencyid int, w http.Respons
return
}
// listen opens a http server listening and serving request
func (ams *AMS) listen() (err error) {
mux := http.NewServeMux()
mux.HandleFunc("/api/", ams.handleAPI)
s := &http.Server{
Addr: ":9000",
Handler: mux,
// server creates the ams server
func (ams *AMS) server(port int) (serv *http.Server) {
r := mux.NewRouter()
// r.HandleFunc("/api/", ams.handleAPI)
s := r.PathPrefix("/api").Subrouter()
// s.HandleFunc("/clonemap", ams.handleCloneMAP)
s.PathPrefix("").HandlerFunc(ams.handleAPI)
serv = &http.Server{
Addr: ":" + strconv.Itoa(port),
Handler: r,
}
ams.logInfo.Println("AMS listening on port 9000")
err = s.ListenAndServe()
return
}
// listen opens a http server listening and serving request
func (ams *AMS) listen(serv *http.Server) (err error) {
ams.logInfo.Println("AMS listening on " + serv.Addr)
err = serv.ListenAndServe()
return
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment