rest

package
v0.0.0-...-070e9cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 19 Imported by: 0

README

/api

This directory is for REST API (Echo) configurations such as routes and middleware.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidDateTime

func IsValidDateTime(formatStr string) func(fl validator.FieldLevel) bool

Custom validator for go-playground/validator Checks if the field is a valid string time can parse

func IsValidDateTimeFormat

func IsValidDateTimeFormat(v interface{}) error

Custom rule for ozzo-validation Checks if the value is a valid DateTime format which time can parse. This rule does not check more than precision in seconds.

func NewCORSMiddleware

func NewCORSMiddleware(cfg *Config) echo.MiddlewareFunc

func NewCSRFMiddleware

func NewCSRFMiddleware(cfg *Config) echo.MiddlewareFunc

func NewHTTPErrorHandler

func NewHTTPErrorHandler(cfg *Config) func(err error, c echo.Context)

func NewJWTMiddleware

func NewJWTMiddleware(cfg *Config) echo.MiddlewareFunc

func NewJWTRefreshMiddleware

func NewJWTRefreshMiddleware(cfg *Config) echo.MiddlewareFunc

func NewRequestValidator

func NewRequestValidator(cfg *Config) *requestValidator

func RequestValidatorStrictHandlerFunc

func RequestValidatorStrictHandlerFunc(f oapi.StrictHandlerFunc, operationID string) oapi.StrictHandlerFunc

Types

type APIResponse

type APIResponse struct {
	Error *app.AppError `json:"error"`
	Data  interface{}   `json:"data"`
}

type Config

type Config struct {
	Environment    EnvironmentType
	APIPort        string
	AllowedOrigins []string

	TLSCertificate string
	TLSKey         string

	// DateTime format used for all request/responses
	APIDateTimeFormat string

	AuthJWTCookieName       string
	AuthJWTSigningMethod    *jwt.SigningMethodHMAC
	AuthJWTSecret           string
	AuthJWTExpireSeconds    int
	RefreshJWTCookieName    string
	RefreshJWTSigningMethod *jwt.SigningMethodHMAC
	RefreshJWTSecret        string
	RefreshJWTExpireSeconds int

	DBHost     string
	DBPort     string
	DBDatabase string
	DBUser     string
	DBPassword string
}

func NewConfig

func NewConfig() *Config

func (*Config) Load

func (c *Config) Load() error

type CustomCtxKey

type CustomCtxKey string
const (
	CtxClaimsKey CustomCtxKey = "claims"
)

type EnvironmentType

type EnvironmentType string
const (
	EnvironmentLocal      EnvironmentType = "local"
	EnvironmentProduction EnvironmentType = "production"
)

type Handler

type Handler struct {
	Config *Config
}

func NewHandler

func NewHandler(cfg *Config) *Handler

func (*Handler) GetClaims

func (h *Handler) GetClaims(ctx context.Context) *auth.JWTClaims

Retrieve JWT Claims from request headers

func (*Handler) Validate

func (h *Handler) Validate(c echo.Context, req interface{}) error

Binds body/params to an interface, and validates. Interface must be a pointer

type IAPIHandler

type IAPIHandler interface {
	GetJWTTokenClaims(c echo.Context) *auth.JWTClaims
	Validate(c echo.Context, req interface{}) error
	CreateResponse(err error, data interface{}) *APIResponse
	CreateErrorResponse(err error) *APIResponse
}

Default interface for API Handlers I'm not entirely sure if we need this?

Directories

Path Synopsis
Package oapi provides primitives to interact with the openapi HTTP API.
Package oapi provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL