initial commit

This commit is contained in:
Mike Mason
2023-07-01 00:04:52 +00:00
commit 80fb879ef6
65 changed files with 3544 additions and 0 deletions

22
internal/routes/errors.go Normal file
View 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")
)

View 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
View 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
}