You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
708 B
Go
35 lines
708 B
Go
package api
|
|
|
|
import (
|
|
. "github.com/containrrr/watchtower/pkg/api/prelude"
|
|
"net/http"
|
|
)
|
|
|
|
type router map[string]methodHandlers
|
|
|
|
type methodHandlers map[string]HandlerFunc
|
|
|
|
func (mh methodHandlers) Handler(c *Context) Response {
|
|
handler, found := mh[c.Request.Method]
|
|
if !found {
|
|
return Error(ErrNotFound)
|
|
}
|
|
return handler(c)
|
|
}
|
|
|
|
func (mh methodHandlers) post(handlerFunc HandlerFunc) {
|
|
mh[http.MethodPost] = handlerFunc
|
|
}
|
|
func (mh methodHandlers) get(handlerFunc HandlerFunc) {
|
|
mh[http.MethodGet] = handlerFunc
|
|
}
|
|
|
|
func (r router) route(route string) methodHandlers {
|
|
routeMethods, found := r[route]
|
|
if !found {
|
|
routeMethods = methodHandlers{}
|
|
r[route] = routeMethods
|
|
}
|
|
return routeMethods
|
|
}
|