Cleaned up and changed router variable names
This commit is contained in:
parent
cd1ea7c7cb
commit
7a8eaeab05
23
router.go
23
router.go
@ -6,12 +6,12 @@ import (
|
||||
"somehole.com/service/router"
|
||||
)
|
||||
|
||||
type Endpoints struct {
|
||||
type Endpoint struct {
|
||||
CallbackEndpoint string
|
||||
TokenEndpoint string
|
||||
}
|
||||
|
||||
var defaultEndpoints = Endpoints{
|
||||
var endpointDefault = Endpoint{
|
||||
CallbackEndpoint: "/callback",
|
||||
TokenEndpoint: "/token",
|
||||
}
|
||||
@ -19,27 +19,30 @@ var defaultEndpoints = Endpoints{
|
||||
type Router struct {
|
||||
*router.Router
|
||||
log.Logger
|
||||
Endpoints
|
||||
Endpoint
|
||||
}
|
||||
|
||||
func NewRouter(r *router.Router, logger log.Logger, endpointOverride ...Endpoints) (ro *Router) {
|
||||
var endpoints Endpoints
|
||||
func NewRouter(r *router.Router, logger log.Logger, endpointOverride ...Endpoint) (ro *Router) {
|
||||
var endpoints Endpoint
|
||||
if r == nil {
|
||||
r = router.NewRouter(nil, nil)
|
||||
}
|
||||
if len(endpointOverride) == 1 {
|
||||
endpoints = endpointOverride[0]
|
||||
} else {
|
||||
endpoints = defaultEndpoints
|
||||
endpoints = endpointDefault
|
||||
}
|
||||
r.AddRequiredRoutes([]string{endpoints.CallbackEndpoint, endpoints.TokenEndpoint})
|
||||
r.AddRequiredRoutes([]string{
|
||||
endpoints.CallbackEndpoint,
|
||||
endpoints.TokenEndpoint,
|
||||
})
|
||||
if logger == nil {
|
||||
logger = log.NewPlainLogger()
|
||||
}
|
||||
return &Router{
|
||||
Router: r,
|
||||
Logger: logger,
|
||||
Endpoints: endpoints,
|
||||
Router: r,
|
||||
Logger: logger,
|
||||
Endpoint: endpoints,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user