7 changed files with 69 additions and 4 deletions
@ -0,0 +1,51 @@
|
||||
/* |
||||
------------------------------------------------------------------------------------------------------------------------ |
||||
####### router ####### Copyright (c) 2021 mls-361 ################################################## MIT License ####### |
||||
------------------------------------------------------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
package router |
||||
|
||||
import ( |
||||
"net/http" |
||||
|
||||
"github.com/julienschmidt/httprouter" |
||||
|
||||
"forge.chapril.org/armen/armen/internal/components" |
||||
) |
||||
|
||||
type router struct { |
||||
mux *httprouter.Router |
||||
} |
||||
|
||||
func newRouter() *router { |
||||
return &router{ |
||||
mux: httprouter.New(), |
||||
} |
||||
} |
||||
|
||||
// Build AFAIRE.
|
||||
func Build(logger components.Logger) *router { |
||||
cr := newRouter() |
||||
|
||||
cr.mux.PanicHandler = func(rw http.ResponseWriter, _ *http.Request, _ interface{}) { |
||||
//AFINIR: logger
|
||||
rw.WriteHeader(http.StatusInternalServerError) |
||||
} |
||||
|
||||
return cr |
||||
} |
||||
|
||||
// Get AFAIRE.
|
||||
func (cr *router) Get(path string, handler http.Handler) { |
||||
cr.mux.Handler(http.MethodGet, path, handler) |
||||
} |
||||
|
||||
// Post AFAIRE.
|
||||
func (cr *router) Post(path string, handler http.Handler) { |
||||
cr.mux.Handler(http.MethodPost, path, handler) |
||||
} |
||||
|
||||
/* |
||||
######################################################################################################## @(°_°)@ ####### |
||||
*/ |
Loading…
Reference in new issue