app

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module(
	"vef:app",
	fx.Provide(New),
)

Functions

func MapFiberError

func MapFiberError(statusCode int) (code int, messageKey string, ok bool)

MapFiberError maps a Fiber HTTP status code to a business error code and i18n message key. Returns ErrCodeUnknown and ErrMessageUnknown if no mapping exists.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App represents the VEF application server. It wraps a Fiber application and manages the HTTP server lifecycle.

func New

func New(params AppParams) (*App, error)

New creates a new VEF application instance with the provided dependencies. Returns an error if the application cannot be configured properly.

func (*App) Start

func (a *App) Start() <-chan error

Start starts the VEF application HTTP server. It returns a channel that will receive nil when the server is ready, or an error if the server fails to start. The server runs in a goroutine and can be stopped using the Stop method.

func (*App) Stop

func (a *App) Stop() error

Stop gracefully shuts down the VEF application server. It waits up to 30 seconds for active connections to close.

func (*App) Test

func (a *App) Test(req *http.Request, timeout ...time.Duration) (*http.Response, error)

Test sends an HTTP request to the application for testing purposes. This method is designed for unit and integration tests. The optional timeout parameter specifies the maximum duration to wait for a response. If no timeout is provided or timeout is zero, a default timeout of 5 seconds is used. This is higher than Fiber's default (1s) to accommodate CI environments.

type AppParams

type AppParams struct {
	fx.In

	Config      *config.AppConfig
	Middlewares []Middleware `group:"vef:app:middlewares"`
	APIEngine   api.Engine
}

AppParams contains all dependencies required to create a VEF application.

type CustomCtx

type CustomCtx struct {
	fiber.DefaultCtx
	// contains filtered or unexported fields
}

CustomCtx is a custom Fiber context that extends the default context with additional framework-specific functionality like logger, principal, and database access.

func (*CustomCtx) DB

func (c *CustomCtx) DB() orm.DB

DB returns the database connection for the current request.

func (*CustomCtx) Logger

func (c *CustomCtx) Logger() log.Logger

Logger returns the logger instance for the current request.

func (*CustomCtx) Principal

func (c *CustomCtx) Principal() *security.Principal

Principal returns the authenticated principal (user/system/app) for the current request.

func (*CustomCtx) SetDB

func (c *CustomCtx) SetDB(db orm.DB)

SetDB sets the database connection for the current request.

func (*CustomCtx) SetLogger

func (c *CustomCtx) SetLogger(logger log.Logger)

SetLogger sets the logger instance for the current request.

func (*CustomCtx) SetPrincipal

func (c *CustomCtx) SetPrincipal(principal *security.Principal)

SetPrincipal sets the authenticated principal for the current request.

type Middleware

type Middleware interface {
	// Name returns the name of the middleware.
	Name() string
	// Order returns the order of the middleware.
	Order() int
	// Apply applies the middleware to the router.
	Apply(router fiber.Router)
}

Middleware is a middleware for the app.

type StructValidator

type StructValidator struct{}

StructValidator implements Fiber's struct validator interface.

func (*StructValidator) Validate

func (*StructValidator) Validate(out any) error

Validate delegates to the framework's validator.

Jump to

Keyboard shortcuts

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