mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-16 23:20:12 +01:00
feat(api): implement new api handler
This commit is contained in:
parent
72e437f173
commit
47091761a5
17 changed files with 571 additions and 294 deletions
34
pkg/api/router.go
Normal file
34
pkg/api/router.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue