initial commit
This commit is contained in:
22
internal/routes/errors.go
Normal file
22
internal/routes/errors.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrInvalidJWTPrivateKeyType is returned when the private key type is not of an expected value.
|
||||
ErrInvalidJWTPrivateKeyType = errors.New("invalid JWT private key provided")
|
||||
|
||||
// ErrAuthTokenHeaderRequired is returned when a token check request is made, but the Authorization header is missing.
|
||||
ErrAuthTokenHeaderRequired = echo.NewHTTPError(http.StatusBadRequest, "header Authorization missing or invalid")
|
||||
|
||||
// ErrInvalidSigningMethod is returned when defined jwt signing method is not recognized.
|
||||
ErrInvalidSigningMethod = errors.New("unrecognized jwt signing method provided")
|
||||
|
||||
// ErrMissingIssuer is returned when the jwt issuer is not defined in the config.
|
||||
ErrMissingIssuer = errors.New("jwt issuer required")
|
||||
)
|
||||
27
internal/routes/options.go
Normal file
27
internal/routes/options.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"go.equinixmetal.net/infra9-metal-bridge/internal/service"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Option is a functional configuration option for the router.
|
||||
type Option func(r *Router) error
|
||||
|
||||
// WithLogger sets the logger for the router.
|
||||
func WithLogger(logger *zap.Logger) Option {
|
||||
return func(r *Router) error {
|
||||
r.logger = logger
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithService sets the service handler.
|
||||
func WithService(svc service.Service) Option {
|
||||
return func(r *Router) error {
|
||||
r.svc = svc
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
32
internal/routes/routes.go
Normal file
32
internal/routes/routes.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Package routes provides the routes for the application.
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"go.equinixmetal.net/infra9-metal-bridge/internal/service"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Router is the router for the application.
|
||||
type Router struct {
|
||||
logger *zap.Logger
|
||||
svc service.Service
|
||||
}
|
||||
|
||||
// Routes registers the routes for the application.
|
||||
func (r *Router) Routes(g *echo.Group) {}
|
||||
|
||||
// NewRouter creates a new router
|
||||
func NewRouter(opts ...Option) (*Router, error) {
|
||||
router := Router{
|
||||
logger: zap.NewNop(),
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
if err := opt(&router); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &router, nil
|
||||
}
|
||||
Reference in New Issue
Block a user