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"
|
"somehole.com/service/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Endpoints struct {
|
type Endpoint struct {
|
||||||
CallbackEndpoint string
|
CallbackEndpoint string
|
||||||
TokenEndpoint string
|
TokenEndpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultEndpoints = Endpoints{
|
var endpointDefault = Endpoint{
|
||||||
CallbackEndpoint: "/callback",
|
CallbackEndpoint: "/callback",
|
||||||
TokenEndpoint: "/token",
|
TokenEndpoint: "/token",
|
||||||
}
|
}
|
||||||
@ -19,27 +19,30 @@ var defaultEndpoints = Endpoints{
|
|||||||
type Router struct {
|
type Router struct {
|
||||||
*router.Router
|
*router.Router
|
||||||
log.Logger
|
log.Logger
|
||||||
Endpoints
|
Endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(r *router.Router, logger log.Logger, endpointOverride ...Endpoints) (ro *Router) {
|
func NewRouter(r *router.Router, logger log.Logger, endpointOverride ...Endpoint) (ro *Router) {
|
||||||
var endpoints Endpoints
|
var endpoints Endpoint
|
||||||
if r == nil {
|
if r == nil {
|
||||||
r = router.NewRouter(nil, nil)
|
r = router.NewRouter(nil, nil)
|
||||||
}
|
}
|
||||||
if len(endpointOverride) == 1 {
|
if len(endpointOverride) == 1 {
|
||||||
endpoints = endpointOverride[0]
|
endpoints = endpointOverride[0]
|
||||||
} else {
|
} else {
|
||||||
endpoints = defaultEndpoints
|
endpoints = endpointDefault
|
||||||
}
|
}
|
||||||
r.AddRequiredRoutes([]string{endpoints.CallbackEndpoint, endpoints.TokenEndpoint})
|
r.AddRequiredRoutes([]string{
|
||||||
|
endpoints.CallbackEndpoint,
|
||||||
|
endpoints.TokenEndpoint,
|
||||||
|
})
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
logger = log.NewPlainLogger()
|
logger = log.NewPlainLogger()
|
||||||
}
|
}
|
||||||
return &Router{
|
return &Router{
|
||||||
Router: r,
|
Router: r,
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
Endpoints: endpoints,
|
Endpoint: endpoints,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user