Cleaned up and changed router variable names

This commit is contained in:
some 2024-10-09 11:56:33 -04:00
parent cd1ea7c7cb
commit 7a8eaeab05
Signed by: some
GPG Key ID: 65D0589220B9BFC8

View File

@ -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,
}
}