diff --git a/go.mod b/go.mod index 7ed33b19..535106c7 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect - github.com/gorilla/mux v1.8.0 + github.com/go-chi/chi/v5 v5.0.8 github.com/json-iterator/go v1.1.10 github.com/pkg/errors v0.8.1 ) diff --git a/go.sum b/go.sum index 9f9f6604..df5dc4dd 100644 --- a/go.sum +++ b/go.sum @@ -7,9 +7,9 @@ github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojt github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y= github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0= +github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= +github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= diff --git a/mock.go b/mock.go index 3dc6003b..86e368e4 100644 --- a/mock.go +++ b/mock.go @@ -12,7 +12,7 @@ import ( "strings" "sync" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) type MockServer interface { @@ -110,9 +110,9 @@ func NewMockServer() MockServer { ms := mockServer{} // Add all our handlers - r := mux.NewRouter() + r := chi.NewRouter() - func(r *mux.Router) { + r.Route("/v3", func(r chi.Router) { ms.addIPRoutes(r) ms.addExportRoutes(r) ms.addDomainRoutes(r) @@ -129,7 +129,7 @@ func NewMockServer() MockServer { ms.addCredentialsRoutes(r) ms.addStatsRoutes(r) ms.addTagsRoutes(r) - }(r.PathPrefix("/v3").Subrouter()) + }) ms.addValidationRoutes(r) // Start the server diff --git a/mock_bounces.go b/mock_bounces.go index b835e374..099b3c0e 100644 --- a/mock_bounces.go +++ b/mock_bounces.go @@ -8,15 +8,15 @@ import ( "net/url" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addBouncesRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/bounces", ms.listBounces).Methods(http.MethodGet) - r.HandleFunc("/{domain}/bounces/{address}", ms.getBounce).Methods(http.MethodGet) - r.HandleFunc("/{domain}/bounces/{address}", ms.deleteBounce).Methods(http.MethodDelete) - r.HandleFunc("/{domain}/bounces", ms.deleteBouncesList).Methods(http.MethodDelete) - r.HandleFunc("/{domain}/bounces", ms.createBounce).Methods(http.MethodPost) +func (ms *mockServer) addBouncesRoutes(r chi.Router) { + r.Get("/{domain}/bounces", ms.listBounces) + r.Get("/{domain}/bounces/{address}", ms.getBounce) + r.Delete("/{domain}/bounces/{address}", ms.deleteBounce) + r.Delete("/{domain}/bounces", ms.deleteBouncesList) + r.Post("/{domain}/bounces", ms.createBounce) ms.bounces = append(ms.bounces, Bounce{ CreatedAt: RFC2822Time(time.Now()), @@ -97,7 +97,7 @@ func (ms *mockServer) getBounce(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, bounce := range ms.bounces { - if bounce.Address == mux.Vars(r)["address"] { + if bounce.Address == chi.URLParam(r, "address") { toJSON(w, bounce) return } @@ -169,7 +169,7 @@ func (ms *mockServer) deleteBounce(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for i, bounce := range ms.bounces { - if bounce.Address == mux.Vars(r)["address"] { + if bounce.Address == chi.URLParam(r, "address") { ms.bounces = append(ms.bounces[:i], ms.bounces[i+1:len(ms.bounces)]...) toJSON(w, map[string]interface{}{ diff --git a/mock_complaints.go b/mock_complaints.go index e6f89b41..f09b906f 100644 --- a/mock_complaints.go +++ b/mock_complaints.go @@ -8,14 +8,14 @@ import ( "net/url" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addComplaintsRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/complaints", ms.listComplaints).Methods(http.MethodGet) - r.HandleFunc("/{domain}/complaints/{address}", ms.getComplaint).Methods(http.MethodGet) - r.HandleFunc("/{domain}/complaints/{address}", ms.deleteComplaint).Methods(http.MethodDelete) - r.HandleFunc("/{domain}/complaints", ms.createComplaint).Methods(http.MethodPost) +func (ms *mockServer) addComplaintsRoutes(r chi.Router) { + r.Get("/{domain}/complaints", ms.listComplaints) + r.Get("/{domain}/complaints/{address}", ms.getComplaint) + r.Delete("/{domain}/complaints/{address}", ms.deleteComplaint) + r.Post("/{domain}/complaints", ms.createComplaint) ms.complaints = append(ms.complaints, Complaint{ CreatedAt: RFC2822Time(time.Now()), @@ -92,7 +92,7 @@ func (ms *mockServer) getComplaint(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, complaint := range ms.complaints { - if complaint.Address == mux.Vars(r)["address"] { + if complaint.Address == chi.URLParam(r, "address") { toJSON(w, complaint) return } @@ -162,7 +162,7 @@ func (ms *mockServer) deleteComplaint(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for i, complaint := range ms.complaints { - if complaint.Address == mux.Vars(r)["address"] { + if complaint.Address == chi.URLParam(r, "address") { ms.complaints = append(ms.complaints[:i], ms.complaints[i+1:len(ms.complaints)]...) toJSON(w, map[string]interface{}{ diff --git a/mock_credentials.go b/mock_credentials.go index 788ef368..0e2a4c6f 100644 --- a/mock_credentials.go +++ b/mock_credentials.go @@ -4,14 +4,14 @@ import ( "net/http" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addCredentialsRoutes(r *mux.Router) { - r.HandleFunc("/domains/{domain}/credentials", ms.listCredentials).Methods(http.MethodGet) - r.HandleFunc("/domains/{domain}/credentials/{login}", ms.updateCredential).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}/credentials/{login}", ms.deleteCredential).Methods(http.MethodDelete) - r.HandleFunc("/domains/{domain}/credentials", ms.createCredential).Methods(http.MethodPost) +func (ms *mockServer) addCredentialsRoutes(r chi.Router) { + r.Get("/domains/{domain}/credentials", ms.listCredentials) + r.Put("/domains/{domain}/credentials/{login}", ms.updateCredential) + r.Delete("/domains/{domain}/credentials/{login}", ms.deleteCredential) + r.Post("/domains/{domain}/credentials", ms.createCredential) ms.credentials = append(ms.credentials, Credential{ CreatedAt: RFC2822Time(time.Now()), @@ -103,8 +103,8 @@ func (ms *mockServer) deleteCredential(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - login := mux.Vars(r)["login"] - domain := mux.Vars(r)["domain"] + login := chi.URLParam(r, "login") + domain := chi.URLParam(r, "domain") for i, credential := range ms.credentials { if credential.Login == login || credential.Login == login+"@"+domain { @@ -127,8 +127,8 @@ func (ms *mockServer) updateCredential(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - domain := mux.Vars(r)["domain"] - login := mux.Vars(r)["login"] + domain := chi.URLParam(r, "domain") + login := chi.URLParam(r, "login") if err := r.ParseForm(); err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(err.Error())) diff --git a/mock_domains.go b/mock_domains.go index aa457870..00fe5082 100644 --- a/mock_domains.go +++ b/mock_domains.go @@ -4,7 +4,7 @@ import ( "net/http" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) type DomainContainer struct { @@ -16,7 +16,7 @@ type DomainContainer struct { TagLimits *TagLimits `json:"limits,omitempty"` } -func (ms *mockServer) addDomainRoutes(r *mux.Router) { +func (ms *mockServer) addDomainRoutes(r chi.Router) { ms.domainList = append(ms.domainList, DomainContainer{ Domain: Domain{ @@ -81,24 +81,24 @@ func (ms *mockServer) addDomainRoutes(r *mux.Router) { }, }) - r.HandleFunc("/domains", ms.listDomains).Methods(http.MethodGet) - r.HandleFunc("/domains", ms.createDomain).Methods(http.MethodPost) - r.HandleFunc("/domains/{domain}", ms.getDomain).Methods(http.MethodGet) - r.HandleFunc("/domains/{domain}/verify", ms.getDomain).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}", ms.deleteDomain).Methods(http.MethodDelete) - //r.HandleFunc("/domains/{domain}/credentials", ms.getCredentials).Methods(http.MethodGet) - //r.HandleFunc("/domains/{domain}/credentials", ms.createCredentials).Methods(http.MethodPost) - //r.HandleFunc("/domains/{domain}/credentials/{login}", ms.updateCredentials).Methods(http.MethodPut) - //r.HandleFunc("/domains/{domain}/credentials/{login}", ms.deleteCredentials).Methods(http.MethodDelete) - r.HandleFunc("/domains/{domain}/connection", ms.getConnection).Methods(http.MethodGet) - r.HandleFunc("/domains/{domain}/connection", ms.updateConnection).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}/tracking", ms.getTracking).Methods(http.MethodGet) - r.HandleFunc("/domains/{domain}/tracking/click", ms.updateClickTracking).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}/tracking/open", ms.updateOpenTracking).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}/tracking/unsubscribe", ms.updateUnsubTracking).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}/limits/tag", ms.getTagLimits).Methods(http.MethodGet) - r.HandleFunc("/domains/{domain}/dkim_selector", ms.updateDKIMSelector).Methods(http.MethodPut) - r.HandleFunc("/domains/{domain}/web_prefix", ms.updateWebPrefix).Methods(http.MethodPut) + r.Get("/domains", ms.listDomains) + r.Post("/domains", ms.createDomain) + r.Get("/domains/{domain}", ms.getDomain) + r.Put("/domains/{domain}/verify", ms.getDomain) + r.Delete("/domains/{domain}", ms.deleteDomain) + //r.Get("/domains/{domain}/credentials", ms.getCredentials) + //r.Post("/domains/{domain}/credentials", ms.createCredentials) + //r.Put("/domains/{domain}/credentials/{login}", ms.updateCredentials) + //r.Delete("/domains/{domain}/credentials/{login}", ms.deleteCredentials) + r.Get("/domains/{domain}/connection", ms.getConnection) + r.Put("/domains/{domain}/connection", ms.updateConnection) + r.Get("/domains/{domain}/tracking", ms.getTracking) + r.Put("/domains/{domain}/tracking/click", ms.updateClickTracking) + r.Put("/domains/{domain}/tracking/open", ms.updateOpenTracking) + r.Put("/domains/{domain}/tracking/unsubscribe", ms.updateUnsubTracking) + r.Get("/domains/{domain}/limits/tag", ms.getTagLimits) + r.Put("/domains/{domain}/dkim_selector", ms.updateDKIMSelector) + r.Put("/domains/{domain}/web_prefix", ms.updateWebPrefix) } func (ms *mockServer) listDomains(w http.ResponseWriter, r *http.Request) { @@ -145,7 +145,7 @@ func (ms *mockServer) getDomain(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { d.Connection = nil toJSON(w, d) return @@ -179,7 +179,7 @@ func (ms *mockServer) deleteDomain(w http.ResponseWriter, r *http.Request) { result := ms.domainList[:0] for _, domain := range ms.domainList { - if domain.Domain.Name == mux.Vars(r)["domain"] { + if domain.Domain.Name == chi.URLParam(r, "domain") { continue } result = append(result, domain) @@ -200,7 +200,7 @@ func (ms *mockServer) getConnection(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { resp := domainConnectionResponse{ Connection: *d.Connection, } @@ -217,7 +217,7 @@ func (ms *mockServer) updateConnection(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for i, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { ms.domainList[i].Connection = &DomainConnection{ RequireTLS: stringToBool(r.FormValue("require_tls")), SkipVerification: stringToBool(r.FormValue("skip_verification")), @@ -235,7 +235,7 @@ func (ms *mockServer) getTracking(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { resp := domainTrackingResponse{ Tracking: *d.Tracking, } @@ -252,7 +252,7 @@ func (ms *mockServer) updateClickTracking(w http.ResponseWriter, r *http.Request ms.mutex.Lock() for i, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { ms.domainList[i].Tracking.Click.Active = stringToBool(r.FormValue("active")) toJSON(w, okResp{Message: "Domain tracking settings have been updated"}) return @@ -267,7 +267,7 @@ func (ms *mockServer) updateOpenTracking(w http.ResponseWriter, r *http.Request) ms.mutex.Lock() for i, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { ms.domainList[i].Tracking.Open.Active = stringToBool(r.FormValue("active")) toJSON(w, okResp{Message: "Domain tracking settings have been updated"}) return @@ -282,7 +282,7 @@ func (ms *mockServer) updateUnsubTracking(w http.ResponseWriter, r *http.Request ms.mutex.Lock() for i, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { ms.domainList[i].Tracking.Unsubscribe.Active = stringToBool(r.FormValue("active")) if len(r.FormValue("html_footer")) != 0 { ms.domainList[i].Tracking.Unsubscribe.HTMLFooter = r.FormValue("html_footer") @@ -303,7 +303,7 @@ func (ms *mockServer) getTagLimits(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { if d.TagLimits == nil { w.WriteHeader(http.StatusNotFound) toJSON(w, okResp{Message: "no limits defined for domain"}) @@ -322,7 +322,7 @@ func (ms *mockServer) updateDKIMSelector(w http.ResponseWriter, r *http.Request) ms.mutex.Lock() for _, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { if r.FormValue("dkim_selector") == "" { toJSON(w, okResp{Message: "dkim_selector param required"}) return @@ -340,7 +340,7 @@ func (ms *mockServer) updateWebPrefix(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, d := range ms.domainList { - if d.Domain.Name == mux.Vars(r)["domain"] { + if d.Domain.Name == chi.URLParam(r, "domain") { if r.FormValue("web_prefix") == "" { toJSON(w, okResp{Message: "web_prefix param required"}) return diff --git a/mock_events.go b/mock_events.go index 7a3a8f67..c0a88a1a 100644 --- a/mock_events.go +++ b/mock_events.go @@ -5,12 +5,12 @@ import ( "net/url" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" "github.com/mailgun/mailgun-go/v4/events" ) -func (ms *mockServer) addEventRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/events", ms.listEvents).Methods(http.MethodGet) +func (ms *mockServer) addEventRoutes(r chi.Router) { + r.Get("/{domain}/events", ms.listEvents) var ( tags = []string{"tag1", "tag2"} diff --git a/mock_exports.go b/mock_exports.go index 54642ada..737d5cf3 100644 --- a/mock_exports.go +++ b/mock_exports.go @@ -4,14 +4,14 @@ import ( "net/http" "strconv" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addExportRoutes(r *mux.Router) { - r.HandleFunc("/exports", ms.postExports).Methods(http.MethodPost) - r.HandleFunc("/exports", ms.listExports).Methods(http.MethodGet) - r.HandleFunc("/exports/{id}", ms.getExport).Methods(http.MethodGet) - r.HandleFunc("/exports/{id}/download_url", ms.getExportLink).Methods(http.MethodGet) +func (ms *mockServer) addExportRoutes(r chi.Router) { + r.Post("/exports", ms.postExports) + r.Get("/exports", ms.listExports) + r.Get("/exports/{id}", ms.getExport) + r.Get("/exports/{id}/download_url", ms.getExportLink) } func (ms *mockServer) postExports(w http.ResponseWriter, r *http.Request) { @@ -39,7 +39,7 @@ func (ms *mockServer) getExport(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() for _, export := range ms.exportList { - if export.ID == mux.Vars(r)["id"] { + if export.ID == chi.URLParam(r, "id") { toJSON(w, export) return } diff --git a/mock_ips.go b/mock_ips.go index 8f59fa6a..12fbd19b 100644 --- a/mock_ips.go +++ b/mock_ips.go @@ -3,18 +3,18 @@ package mailgun import ( "net/http" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addIPRoutes(r *mux.Router) { - r.HandleFunc("/ips", ms.listIPS).Methods(http.MethodGet) - r.HandleFunc("/ips/{ip}", ms.getIPAddress).Methods(http.MethodGet) - func(r *mux.Router) { - r.HandleFunc("", ms.listDomainIPS).Methods(http.MethodGet) - r.HandleFunc("/{ip}", ms.getIPAddress).Methods(http.MethodGet) - r.HandleFunc("", ms.postDomainIPS).Methods(http.MethodPost) - r.HandleFunc("/{ip}", ms.deleteDomainIPS).Methods(http.MethodDelete) - }(r.PathPrefix("/domains/{domain}/ips").Subrouter()) +func (ms *mockServer) addIPRoutes(r chi.Router) { + r.Get("/ips", ms.listIPS) + r.Get("/ips/{ip}", ms.getIPAddress) + r.Route("/domains/{domain}/ips", func(r chi.Router) { + r.Get("/", ms.listDomainIPS) + r.Get("/{ip}", ms.getIPAddress) + r.Post("/", ms.postDomainIPS) + r.Delete("/{ip}", ms.deleteDomainIPS) + }) } func (ms *mockServer) listIPS(w http.ResponseWriter, _ *http.Request) { @@ -26,7 +26,7 @@ func (ms *mockServer) listIPS(w http.ResponseWriter, _ *http.Request) { func (ms *mockServer) getIPAddress(w http.ResponseWriter, r *http.Request) { toJSON(w, IPAddress{ - IP: mux.Vars(r)["ip"], + IP: chi.URLParam(r, "ip"), RDNS: "luna.mailgun.net", Dedicated: true, }) @@ -53,7 +53,7 @@ func (ms *mockServer) deleteDomainIPS(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() result := ms.domainIPS[:0] for _, ip := range ms.domainIPS { - if ip == mux.Vars(r)["ip"] { + if ip == chi.URLParam(r, "ip") { continue } result = append(result, ip) diff --git a/mock_mailing_list.go b/mock_mailing_list.go index 58ce34c2..54822640 100644 --- a/mock_mailing_list.go +++ b/mock_mailing_list.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) type MailingListContainer struct { @@ -14,19 +14,19 @@ type MailingListContainer struct { Members []Member } -func (ms *mockServer) addMailingListRoutes(r *mux.Router) { - r.HandleFunc("/lists/pages", ms.listMailingLists).Methods(http.MethodGet) - r.HandleFunc("/lists/{address}", ms.getMailingList).Methods(http.MethodGet) - r.HandleFunc("/lists", ms.createMailingList).Methods(http.MethodPost) - r.HandleFunc("/lists/{address}", ms.updateMailingList).Methods(http.MethodPut) - r.HandleFunc("/lists/{address}", ms.deleteMailingList).Methods(http.MethodDelete) +func (ms *mockServer) addMailingListRoutes(r chi.Router) { + r.Get("/lists/pages", ms.listMailingLists) + r.Get("/lists/{address}", ms.getMailingList) + r.Post("/lists", ms.createMailingList) + r.Put("/lists/{address}", ms.updateMailingList) + r.Delete("/lists/{address}", ms.deleteMailingList) - r.HandleFunc("/lists/{address}/members/pages", ms.listMembers).Methods(http.MethodGet) - r.HandleFunc("/lists/{address}/members/{member}", ms.getMember).Methods(http.MethodGet) - r.HandleFunc("/lists/{address}/members", ms.createMember).Methods(http.MethodPost) - r.HandleFunc("/lists/{address}/members/{member}", ms.updateMember).Methods(http.MethodPut) - r.HandleFunc("/lists/{address}/members/{member}", ms.deleteMember).Methods(http.MethodDelete) - r.HandleFunc("/lists/{address}/members.json", ms.bulkCreate).Methods(http.MethodPost) + r.Get("/lists/{address}/members/pages", ms.listMembers) + r.Get("/lists/{address}/members/{member}", ms.getMember) + r.Post("/lists/{address}/members", ms.createMember) + r.Put("/lists/{address}/members/{member}", ms.updateMember) + r.Delete("/lists/{address}/members/{member}", ms.deleteMember) + r.Post("/lists/{address}/members.json", ms.bulkCreate) ms.mailingList = append(ms.mailingList, MailingListContainer{ MailingList: MailingList{ @@ -98,7 +98,7 @@ func (ms *mockServer) getMailingList(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { toJSON(w, mailingListResponse{MailingList: ml.MailingList}) return } @@ -113,7 +113,7 @@ func (ms *mockServer) deleteMailingList(w http.ResponseWriter, r *http.Request) result := ms.mailingList[:0] for _, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { continue } result = append(result, ml) @@ -134,7 +134,7 @@ func (ms *mockServer) updateMailingList(w http.ResponseWriter, r *http.Request) ms.mutex.Lock() for i, d := range ms.mailingList { - if d.MailingList.Address == mux.Vars(r)["address"] { + if d.MailingList.Address == chi.URLParam(r, "address") { if r.FormValue("address") != "" { ms.mailingList[i].MailingList.Address = r.FormValue("address") } @@ -184,7 +184,7 @@ func (ms *mockServer) listMembers(w http.ResponseWriter, r *http.Request) { var found bool for _, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { found = true for _, member := range ml.Members { list = append(list, member) @@ -239,10 +239,10 @@ func (ms *mockServer) getMember(w http.ResponseWriter, r *http.Request) { var found bool for _, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { found = true for _, member := range ml.Members { - if member.Address == mux.Vars(r)["member"] { + if member.Address == chi.URLParam(r, "member") { toJSON(w, memberResponse{Member: member}) return } @@ -266,7 +266,7 @@ func (ms *mockServer) deleteMember(w http.ResponseWriter, r *http.Request) { idx := -1 for i, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { idx = i } } @@ -279,7 +279,7 @@ func (ms *mockServer) deleteMember(w http.ResponseWriter, r *http.Request) { result := ms.mailingList[idx].Members[:0] for _, m := range ms.mailingList[idx].Members { - if m.Address == mux.Vars(r)["member"] { + if m.Address == chi.URLParam(r, "member") { continue } result = append(result, m) @@ -301,7 +301,7 @@ func (ms *mockServer) updateMember(w http.ResponseWriter, r *http.Request) { idx := -1 for i, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { idx = i } } @@ -313,7 +313,7 @@ func (ms *mockServer) updateMember(w http.ResponseWriter, r *http.Request) { } for i, m := range ms.mailingList[idx].Members { - if m.Address == mux.Vars(r)["member"] { + if m.Address == chi.URLParam(r, "member") { if r.FormValue("address") != "" { ms.mailingList[idx].Members[i].Address = parseAddress(r.FormValue("address")) } @@ -341,7 +341,7 @@ func (ms *mockServer) createMember(w http.ResponseWriter, r *http.Request) { idx := -1 for i, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { idx = i } } @@ -387,7 +387,7 @@ func (ms *mockServer) bulkCreate(w http.ResponseWriter, r *http.Request) { idx := -1 for i, ml := range ms.mailingList { - if ml.MailingList.Address == mux.Vars(r)["address"] { + if ml.MailingList.Address == chi.URLParam(r, "address") { idx = i } } diff --git a/mock_messages.go b/mock_messages.go index 1048758b..b0c8a6e5 100644 --- a/mock_messages.go +++ b/mock_messages.go @@ -6,16 +6,16 @@ import ( "strings" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" "github.com/mailgun/mailgun-go/v4/events" ) -func (ms *mockServer) addMessagesRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/messages", ms.createMessages).Methods(http.MethodPost) +func (ms *mockServer) addMessagesRoutes(r chi.Router) { + r.Post("/{domain}/messages", ms.createMessages) // This path is made up; it could be anything as the storage url could change over time - r.HandleFunc("/se.storage.url/messages/{id}", ms.getStoredMessages).Methods(http.MethodGet) - r.HandleFunc("/se.storage.url/messages/{id}", ms.sendStoredMessages).Methods(http.MethodPost) + r.Get("/se.storage.url/messages/{id}", ms.getStoredMessages) + r.Post("/se.storage.url/messages/{id}", ms.sendStoredMessages) } // TODO: This implementation doesn't support multiple recipients @@ -102,7 +102,7 @@ func (ms *mockServer) createMessages(w http.ResponseWriter, r *http.Request) { } func (ms *mockServer) getStoredMessages(w http.ResponseWriter, r *http.Request) { - id := mux.Vars(r)["id"] + id := chi.URLParam(r, "id") defer ms.mutex.Unlock() ms.mutex.Lock() @@ -134,7 +134,7 @@ func (ms *mockServer) getStoredMessages(w http.ResponseWriter, r *http.Request) } func (ms *mockServer) sendStoredMessages(w http.ResponseWriter, r *http.Request) { - id := mux.Vars(r)["id"] + id := chi.URLParam(r, "id") defer ms.mutex.Unlock() ms.mutex.Lock() diff --git a/mock_routes.go b/mock_routes.go index 6d3f55a1..ada658c3 100644 --- a/mock_routes.go +++ b/mock_routes.go @@ -5,19 +5,19 @@ import ( "net/http" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) type routeResponse struct { Route Route `json:"route"` } -func (ms *mockServer) addRoutes(r *mux.Router) { - r.HandleFunc("/routes", ms.createRoute).Methods(http.MethodPost) - r.HandleFunc("/routes", ms.listRoutes).Methods(http.MethodGet) - r.HandleFunc("/routes/{id}", ms.getRoute).Methods(http.MethodGet) - r.HandleFunc("/routes/{id}", ms.updateRoute).Methods(http.MethodPut) - r.HandleFunc("/routes/{id}", ms.deleteRoute).Methods(http.MethodDelete) +func (ms *mockServer) addRoutes(r chi.Router) { + r.Post("/routes", ms.createRoute) + r.Get("/routes", ms.listRoutes) + r.Get("/routes/{id}", ms.getRoute) + r.Put("/routes/{id}", ms.updateRoute) + r.Delete("/routes/{id}", ms.deleteRoute) for i := 0; i < 10; i++ { ms.routeList = append(ms.routeList, Route{ @@ -66,7 +66,7 @@ func (ms *mockServer) listRoutes(w http.ResponseWriter, r *http.Request) { func (ms *mockServer) getRoute(w http.ResponseWriter, r *http.Request) { for _, item := range ms.routeList { - if item.Id == mux.Vars(r)["id"] { + if item.Id == chi.URLParam(r, "id") { toJSON(w, routeResponse{Route: item}) return } @@ -104,7 +104,7 @@ func (ms *mockServer) updateRoute(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for i, item := range ms.routeList { - if item.Id == mux.Vars(r)["id"] { + if item.Id == chi.URLParam(r, "id") { if r.FormValue("action") != "" { ms.routeList[i].Actions = r.Form["action"] @@ -132,7 +132,7 @@ func (ms *mockServer) deleteRoute(w http.ResponseWriter, r *http.Request) { result := ms.routeList[:0] for _, item := range ms.routeList { - if item.Id == mux.Vars(r)["id"] { + if item.Id == chi.URLParam(r, "id") { continue } result = append(result, item) diff --git a/mock_stats.go b/mock_stats.go index 47d0c6f9..d1c1dc36 100644 --- a/mock_stats.go +++ b/mock_stats.go @@ -4,12 +4,12 @@ import ( "net/http" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addStatsRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/stats", ms.getStats).Methods(http.MethodGet) - r.HandleFunc("/{domain}/stats/total", ms.getStatsTotal).Methods(http.MethodGet) +func (ms *mockServer) addStatsRoutes(r chi.Router) { + r.Get("/{domain}/stats", ms.getStats) + r.Get("/{domain}/stats/total", ms.getStatsTotal) ms.stats = append(ms.stats, Stats{ Time: "", diff --git a/mock_tags.go b/mock_tags.go index aca42c24..6dc1706f 100644 --- a/mock_tags.go +++ b/mock_tags.go @@ -5,14 +5,14 @@ import ( "net/url" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addTagsRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/tags", ms.listTags).Methods(http.MethodGet) - r.HandleFunc("/{domain}/tags/{tag}", ms.getTags).Methods(http.MethodGet) - r.HandleFunc("/{domain}/tags/{tag}", ms.deleteTags).Methods(http.MethodDelete) - r.HandleFunc("/{domain}/tags/{tag}", ms.createUpdateTags).Methods(http.MethodPut) +func (ms *mockServer) addTagsRoutes(r chi.Router) { + r.Get("/{domain}/tags", ms.listTags) + r.Get("/{domain}/tags/{tag}", ms.getTags) + r.Delete("/{domain}/tags/{tag}", ms.deleteTags) + r.Put("/{domain}/tags/{tag}", ms.createUpdateTags) tenMinutesBefore := time.Now().Add(-10 * time.Minute) now := time.Now() @@ -94,7 +94,7 @@ func (ms *mockServer) getTags(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() for _, tag := range ms.tags { - if tag.Value == mux.Vars(r)["tag"] { + if tag.Value == chi.URLParam(r, "tag") { toJSON(w, tag) return } @@ -113,7 +113,7 @@ func (ms *mockServer) createUpdateTags(w http.ResponseWriter, r *http.Request) { return } - tag := mux.Vars(r)["tag"] + tag := chi.URLParam(r, "tag") description := r.FormValue("description") var tagExists bool @@ -138,7 +138,7 @@ func (ms *mockServer) deleteTags(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for i, existingTag := range ms.tags { - if existingTag.Value == mux.Vars(r)["tag"] { + if existingTag.Value == chi.URLParam(r, "tag") { ms.tags = append(ms.tags[:i], ms.tags[i+1:len(ms.tags)]...) } } diff --git a/mock_template_versions.go b/mock_template_versions.go index 44d04005..d0a862e6 100644 --- a/mock_template_versions.go +++ b/mock_template_versions.go @@ -7,22 +7,22 @@ import ( "strings" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addTemplateVersionRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/templates/{template}/versions", ms.listTemplateVersions).Methods(http.MethodGet) - r.HandleFunc("/{domain}/templates/{template}/versions/{tag}", ms.getTemplateVersion).Methods(http.MethodGet) - r.HandleFunc("/{domain}/templates/{template}/versions", ms.createTemplateVersion).Methods(http.MethodPost) - r.HandleFunc("/{domain}/templates/{template}/versions/{tag}", ms.updateTemplateVersion).Methods(http.MethodPut) - r.HandleFunc("/{domain}/templates/{template}/versions/{tag}", ms.deleteTemplateVersion).Methods(http.MethodDelete) +func (ms *mockServer) addTemplateVersionRoutes(r chi.Router) { + r.Get("/{domain}/templates/{template}/versions", ms.listTemplateVersions) + r.Get("/{domain}/templates/{template}/versions/{tag}", ms.getTemplateVersion) + r.Post("/{domain}/templates/{template}/versions", ms.createTemplateVersion) + r.Put("/{domain}/templates/{template}/versions/{tag}", ms.updateTemplateVersion) + r.Delete("/{domain}/templates/{template}/versions/{tag}", ms.deleteTemplateVersion) } func (ms *mockServer) listTemplateVersions(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["template"] + templateName := chi.URLParam(r, "template") template, found := ms.fetchTemplate(templateName) if !found { w.WriteHeader(http.StatusNotFound) @@ -97,9 +97,9 @@ func (ms *mockServer) getTemplateVersion(w http.ResponseWriter, r *http.Request) defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["template"] + templateName := chi.URLParam(r, "template") templateName = strings.ToLower(templateName) - templateVersionName := mux.Vars(r)["tag"] + templateVersionName := chi.URLParam(r, "tag") templateVersionName = strings.ToLower(templateVersionName) template, templateFound := ms.fetchTemplate(templateName) @@ -127,7 +127,7 @@ func (ms *mockServer) createTemplateVersion(w http.ResponseWriter, r *http.Reque defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["template"] + templateName := chi.URLParam(r, "template") templateName = strings.ToLower(templateName) r.ParseForm() @@ -199,9 +199,9 @@ func (ms *mockServer) updateTemplateVersion(w http.ResponseWriter, r *http.Reque defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["template"] + templateName := chi.URLParam(r, "template") templateName = strings.ToLower(templateName) - templateVersionName := mux.Vars(r)["tag"] + templateVersionName := chi.URLParam(r, "tag") templateVersionName = strings.ToLower(templateVersionName) _, templateFound := ms.fetchTemplate(templateName) @@ -278,9 +278,9 @@ func (ms *mockServer) deleteTemplateVersion(w http.ResponseWriter, r *http.Reque defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["template"] + templateName := chi.URLParam(r, "template") templateName = strings.ToLower(templateName) - templateVersionName := mux.Vars(r)["tag"] + templateVersionName := chi.URLParam(r, "tag") templateVersionName = strings.ToLower(templateVersionName) _, templateFound := ms.fetchTemplate(templateName) diff --git a/mock_templates.go b/mock_templates.go index c4319194..657c8a71 100644 --- a/mock_templates.go +++ b/mock_templates.go @@ -7,17 +7,17 @@ import ( "strings" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addTemplateRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/templates", ms.listTemplates).Methods(http.MethodGet) - r.HandleFunc("/{domain}/templates/{name}", ms.getTemplate).Methods(http.MethodGet) +func (ms *mockServer) addTemplateRoutes(r chi.Router) { + r.Get("/{domain}/templates", ms.listTemplates) + r.Get("/{domain}/templates/{name}", ms.getTemplate) - r.HandleFunc("/{domain}/templates", ms.createTemplate).Methods(http.MethodPost) - r.HandleFunc("/{domain}/templates/{name}", ms.updateTemplate).Methods(http.MethodPut) - r.HandleFunc("/{domain}/templates/{name}", ms.deleteTemplate).Methods(http.MethodDelete) - r.HandleFunc("/{domain}/templates/{name}", ms.deleteAllTemplates).Methods(http.MethodDelete) + r.Post("/{domain}/templates", ms.createTemplate) + r.Put("/{domain}/templates/{name}", ms.updateTemplate) + r.Delete("/{domain}/templates/{name}", ms.deleteTemplate) + r.Delete("/{domain}/templates/{name}", ms.deleteAllTemplates) ms.templates = append(ms.templates, Template{ Name: "template1", @@ -135,7 +135,7 @@ func (ms *mockServer) getTemplate(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["name"] + templateName := chi.URLParam(r, "name") templateName = strings.ToLower(templateName) err := r.ParseForm() @@ -233,7 +233,7 @@ func (ms *mockServer) updateTemplate(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - name := mux.Vars(r)["name"] + name := chi.URLParam(r, "name") if len(name) == 0 { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("{\"message\": \"Missing mandatory parameter: name\"}")) @@ -272,7 +272,7 @@ func (ms *mockServer) deleteTemplate(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - templateName := mux.Vars(r)["name"] + templateName := chi.URLParam(r, "name") for i, template := range ms.templates { if template.Name == templateName { diff --git a/mock_unsubscribes.go b/mock_unsubscribes.go index b961cc6b..e8d5ba69 100644 --- a/mock_unsubscribes.go +++ b/mock_unsubscribes.go @@ -8,14 +8,14 @@ import ( "net/url" "time" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addUnsubscribesRoutes(r *mux.Router) { - r.HandleFunc("/{domain}/unsubscribes", ms.listUnsubscribes).Methods(http.MethodGet) - r.HandleFunc("/{domain}/unsubscribes/{address}", ms.getUnsubscribe).Methods(http.MethodGet) - r.HandleFunc("/{domain}/unsubscribes/{address}", ms.deleteUnsubscribe).Methods(http.MethodDelete) - r.HandleFunc("/{domain}/unsubscribes", ms.createUnsubscribe).Methods(http.MethodPost) +func (ms *mockServer) addUnsubscribesRoutes(r chi.Router) { + r.Get("/{domain}/unsubscribes", ms.listUnsubscribes) + r.Get("/{domain}/unsubscribes/{address}", ms.getUnsubscribe) + r.Delete("/{domain}/unsubscribes/{address}", ms.deleteUnsubscribe) + r.Post("/{domain}/unsubscribes", ms.createUnsubscribe) ms.unsubscribes = append(ms.unsubscribes, Unsubscribe{ CreatedAt: RFC2822Time(time.Now()), @@ -96,7 +96,7 @@ func (ms *mockServer) getUnsubscribe(w http.ResponseWriter, r *http.Request) { ms.mutex.Lock() for _, unsubscribe := range ms.unsubscribes { - if unsubscribe.Address == mux.Vars(r)["address"] { + if unsubscribe.Address == chi.URLParam(r, "address") { toJSON(w, unsubscribe) return } @@ -175,7 +175,7 @@ func (ms *mockServer) deleteUnsubscribe(w http.ResponseWriter, r *http.Request) var addressExist bool for _, unsubscribe := range ms.unsubscribes { - if unsubscribe.Address == mux.Vars(r)["address"] { + if unsubscribe.Address == chi.URLParam(r, "address") { addressExist = true } } @@ -190,7 +190,7 @@ func (ms *mockServer) deleteUnsubscribe(w http.ResponseWriter, r *http.Request) tag := r.FormValue("tag") if len(tag) == 0 { for i, unsubscribe := range ms.unsubscribes { - if unsubscribe.Address != mux.Vars(r)["address"] { + if unsubscribe.Address != chi.URLParam(r, "address") { continue } ms.unsubscribes = append(ms.unsubscribes[:i], ms.unsubscribes[i+1:len(ms.unsubscribes)]...) @@ -203,7 +203,7 @@ func (ms *mockServer) deleteUnsubscribe(w http.ResponseWriter, r *http.Request) } for i, unsubscribe := range ms.unsubscribes { - if unsubscribe.Address != mux.Vars(r)["address"] { + if unsubscribe.Address != chi.URLParam(r, "address") { continue } for j, t := range ms.unsubscribes[i].Tags { diff --git a/mock_validation.go b/mock_validation.go index 6299b2cd..83ce2786 100644 --- a/mock_validation.go +++ b/mock_validation.go @@ -5,15 +5,15 @@ import ( "net/mail" "strings" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addValidationRoutes(r *mux.Router) { - r.HandleFunc("/v3/address/validate", ms.validateEmail).Methods(http.MethodGet) - r.HandleFunc("/v3/address/parse", ms.parseEmail).Methods(http.MethodGet) - r.HandleFunc("/v3/address/private/validate", ms.validateEmail).Methods(http.MethodGet) - r.HandleFunc("/v3/address/private/parse", ms.parseEmail).Methods(http.MethodGet) - r.HandleFunc("/v4/address/validate", ms.validateEmailV4).Methods(http.MethodGet) +func (ms *mockServer) addValidationRoutes(r chi.Router) { + r.Get("/v3/address/validate", ms.validateEmail) + r.Get("/v3/address/parse", ms.parseEmail) + r.Get("/v3/address/private/validate", ms.validateEmail) + r.Get("/v3/address/private/parse", ms.parseEmail) + r.Get("/v4/address/validate", ms.validateEmailV4) } func (ms *mockServer) validateEmailV4(w http.ResponseWriter, r *http.Request) { diff --git a/mock_webhooks.go b/mock_webhooks.go index 3b016547..163870bc 100644 --- a/mock_webhooks.go +++ b/mock_webhooks.go @@ -3,16 +3,17 @@ package mailgun import ( "net/http" - "github.com/gorilla/mux" + "github.com/go-chi/chi/v5" ) -func (ms *mockServer) addWebhookRoutes(r *mux.Router) { - sr := r.PathPrefix("/domains/{domain}/webhooks").Subrouter() - sr.HandleFunc("", ms.listWebHooks).Methods(http.MethodGet) - sr.HandleFunc("", ms.postWebHook).Methods(http.MethodPost) - sr.HandleFunc("/{webhook}", ms.getWebHook).Methods(http.MethodGet) - sr.HandleFunc("/{webhook}", ms.putWebHook).Methods(http.MethodPut) - sr.HandleFunc("/{webhook}", ms.deleteWebHook).Methods(http.MethodDelete) +func (ms *mockServer) addWebhookRoutes(r chi.Router) { + r.Route("/domains/{domain}/webhooks", func(sr chi.Router) { + sr.Get("/", ms.listWebHooks) + sr.Post("/", ms.postWebHook) + sr.Get("/{webhook}", ms.getWebHook) + sr.Put("/{webhook}", ms.putWebHook) + sr.Delete("/{webhook}", ms.deleteWebHook) + }) ms.webhooks = WebHooksListResponse{ Webhooks: map[string]UrlOrUrls{ @@ -39,7 +40,7 @@ func (ms *mockServer) getWebHook(w http.ResponseWriter, r *http.Request) { resp := WebHookResponse{ Webhook: UrlOrUrls{ - Urls: ms.webhooks.Webhooks[mux.Vars(r)["webhook"]].Urls, + Urls: ms.webhooks.Webhooks[chi.URLParam(r, "webhook")].Urls, }, } toJSON(w, resp) @@ -78,7 +79,7 @@ func (ms *mockServer) putWebHook(w http.ResponseWriter, r *http.Request) { for _, url := range r.Form["url"] { urls = append(urls, url) } - ms.webhooks.Webhooks[mux.Vars(r)["webhook"]] = UrlOrUrls{Urls: urls} + ms.webhooks.Webhooks[chi.URLParam(r, "webhook")] = UrlOrUrls{Urls: urls} toJSON(w, okResp{Message: "success"}) } @@ -87,12 +88,12 @@ func (ms *mockServer) deleteWebHook(w http.ResponseWriter, r *http.Request) { defer ms.mutex.Unlock() ms.mutex.Lock() - _, ok := ms.webhooks.Webhooks[mux.Vars(r)["webhook"]] + _, ok := ms.webhooks.Webhooks[chi.URLParam(r, "webhook")] if !ok { w.WriteHeader(http.StatusNotFound) toJSON(w, okResp{Message: "webhook not found"}) } - delete(ms.webhooks.Webhooks, mux.Vars(r)["webhook"]) + delete(ms.webhooks.Webhooks, chi.URLParam(r, "webhook")) toJSON(w, okResp{Message: "success"}) }