core

package
v0.0.0-...-347a58a Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	PATCH  = "PATCH"
)

HTTP Methods

Variables

View Source
var (
	ErrPluginAlreadyRegistered = fiber.NewError(fiber.StatusConflict, "plugin already registered")
	ErrPluginNotFound          = fiber.NewError(fiber.StatusNotFound, "plugin not found")
)

Plugin errors

View Source
var (
	ErrInvalidTarget = fiber.NewError(fiber.StatusInternalServerError, "invalid injection target")
)

Inject errors

Functions

func Adapt

func Adapt(value interface{}, targetType reflect.Type) (interface{}, error)

Adapt attempts to adapt a value to the target type using the global registry

func ApplyMiddleware

func ApplyMiddleware(app *fiber.App, chain *MiddlewareChain)

ApplyMiddleware applies middleware to a fiber app

func ApplyPipes

func ApplyPipes(value interface{}, pipes []PipeMeta) (interface{}, error)

ApplyPipes applies pipes to a value

func AuthMiddleware

func AuthMiddleware(provider AuthProvider) fiber.Handler

AuthMiddleware creates an authentication middleware

func CacheMiddleware

func CacheMiddleware(cache *Cache, expiration time.Duration) fiber.Handler

CacheMiddleware creates a middleware that caches responses

func Controller

func Controller(options ControllerOptions) func(c interface{}) interface{}

Controller decorator for class

func Delete

func Delete(path string, options ...RouteOptions) func(interface{}, string, fiber.Handler)

Delete registers a DELETE route

func Get

func Get(path string, options ...RouteOptions) func(interface{}, string, fiber.Handler)

Get registers a GET route

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv returns an environment variable or a default value

func GetEnvBool

func GetEnvBool(key string, defaultValue bool) bool

GetEnvBool returns an environment variable as a boolean or a default value

func GetEnvInt

func GetEnvInt(key string, defaultValue int) int

GetEnvInt returns an environment variable as an integer or a default value

func GlobalErrorHandler

func GlobalErrorHandler() fiber.Handler

GlobalErrorHandler creates a global error handling middleware

func Learn

func Learn(model interface{}, prefix string, app *fiber.App)

func LoadEnv

func LoadEnv()

func LogMiddleware

func LogMiddleware(logger *Logger) fiber.Handler

LogMiddleware creates a logging middleware

func Module

func Module(options ModuleOptions) func(m interface{}) interface{}

Module decorator for class

func Patch

func Patch(path string, options ...RouteOptions) func(interface{}, string, fiber.Handler)

Patch registers a PATCH route

func PermissionMiddleware

func PermissionMiddleware(permissions ...Permission) fiber.Handler

PermissionMiddleware creates a permission-based authorization middleware

func Post

func Post(path string, options ...RouteOptions) func(interface{}, string, fiber.Handler)

Post registers a POST route

func Put

func Put(path string, options ...RouteOptions) func(interface{}, string, fiber.Handler)

Put registers a PUT route

func RegisterAdapter

func RegisterAdapter(from, to reflect.Type, adapter AdapterFunc)

RegisterAdapter registers a global adapter

func RegisterGuard

func RegisterGuard(controller interface{}, guard Guard)

RegisterGuard adds a guard to the controller's metadata

func RegisterRoute

func RegisterRoute(controller interface{}, opts RouteOptions, handler fiber.Handler)

RegisterRoute adds a new route to the controller's metadata

func RegisterRoutes

func RegisterRoutes(app *fiber.App)

RegisterRoutes registers all controller routes

func RoleMiddleware

func RoleMiddleware(roles ...Role) fiber.Handler

RoleMiddleware creates a role-based authorization middleware

func SaveConfig

func SaveConfig(config *Config, path string) error

SaveConfig saves the configuration to a file

func UseGuards

func UseGuards(guards ...Guard) func(interface{}, string)

UseGuards decorator for method

func UseInterceptor

func UseInterceptor(interceptor Interceptor, options InterceptorOptions) func(interface{}, string)

UseInterceptor decorator for method

func UsePipe

func UsePipe(pipe Pipe, options PipeOptions) func(interface{}, string, int)

UsePipe decorator for method parameter

func UsePipes

func UsePipes(pipes ...PipeMeta) func(interface{}, string)

UsePipes decorator for method

func Validate

func Validate(s interface{}) error

func ValidateRequest

func ValidateRequest(c *fiber.Ctx) error

Types

type AdapterFunc

type AdapterFunc func(interface{}) (interface{}, error)

AdapterFunc is a function that can adapt one type to another

type AdapterRegistry

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

AdapterRegistry stores registered adapters

func NewAdapterRegistry

func NewAdapterRegistry() *AdapterRegistry

NewAdapterRegistry creates a new adapter registry

func (*AdapterRegistry) Adapt

func (r *AdapterRegistry) Adapt(value interface{}, targetType reflect.Type) (interface{}, error)

Adapt attempts to adapt a value to the target type

func (*AdapterRegistry) GetAdapter

func (r *AdapterRegistry) GetAdapter(from, to reflect.Type) (AdapterFunc, bool)

GetAdapter retrieves an adapter for the given types

func (*AdapterRegistry) RegisterAdapter

func (r *AdapterRegistry) RegisterAdapter(from, to reflect.Type, adapter AdapterFunc)

RegisterAdapter registers a new adapter

type App

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

func NewApp

func NewApp() *App

func (*App) GetFiber

func (a *App) GetFiber() *fiber.App

func (*App) Listen

func (a *App) Listen(addr string) error

type AppConfig

type AppConfig struct {
	Port     int    `json:"port"`
	Env      string `json:"env"`
	LogLevel string `json:"logLevel"`
}

AppConfig represents the application configuration

type AuthConfig

type AuthConfig struct {
	Secret string `json:"secret"`
}

AuthConfig represents the authentication configuration

type AuthProvider

type AuthProvider interface {
	Authenticate(ctx *fiber.Ctx) (interface{}, error)
}

AuthProvider defines the interface for authentication providers

type Cache

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

Cache is a thread-safe in-memory cache

func NewCache

func NewCache() *Cache

NewCache creates a new cache

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes an item from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get retrieves an item from the cache

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, expiration time.Duration)

Set adds an item to the cache with an expiration time

type CacheConfig

type CacheConfig struct {
	Enabled bool `json:"enabled"`
	TTL     int  `json:"ttl"`
}

CacheConfig represents the cache configuration

type CacheItem

type CacheItem struct {
	Value      interface{}
	Expiration time.Time
}

CacheItem represents an item in the cache

type Config

type Config struct {
	App      AppConfig      `json:"app"`
	Database DatabaseConfig `json:"database"`
	Auth     AuthConfig     `json:"auth"`
	Cache    CacheConfig    `json:"cache"`
}

Config represents the application configuration

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads the configuration from a file

type Container

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

Container manages dependencies

func NewContainer

func NewContainer() *Container

NewContainer creates a new dependency container

func (*Container) Get

func (c *Container) Get(name string) (interface{}, error)

Get retrieves a service from the container

func (*Container) Inject

func (c *Container) Inject(target interface{}) error

Inject injects dependencies into a struct

func (*Container) Register

func (c *Container) Register(name string, service interface{}) error

Register registers a service with the container

type ControllerMeta

type ControllerMeta struct {
	Instance interface{}
	Path     string
	Guards   []Guard
	Version  string
	Routes   []RouteMeta
}

ControllerMeta stores controller metadata

func GetControllers

func GetControllers() []ControllerMeta

GetControllers returns all registered controllers

type ControllerOptions

type ControllerOptions struct {
	Path    string
	Guards  []Guard
	Version string
}

ControllerOptions defines controller configuration

type DatabaseConfig

type DatabaseConfig struct {
	Driver   string `json:"driver"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Database string `json:"database"`
}

DatabaseConfig represents the database configuration

type DatabaseManager

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

DatabaseManager manages database connections

func NewDatabaseManager

func NewDatabaseManager() *DatabaseManager

NewDatabaseManager creates a new database manager

func (*DatabaseManager) ConnectAll

func (m *DatabaseManager) ConnectAll() error

ConnectAll connects all registered providers

func (*DatabaseManager) DisconnectAll

func (m *DatabaseManager) DisconnectAll() error

DisconnectAll disconnects all registered providers

func (*DatabaseManager) GetProvider

func (m *DatabaseManager) GetProvider(name string) (DatabaseProvider, error)

GetProvider returns a database provider

func (*DatabaseManager) RegisterProvider

func (m *DatabaseManager) RegisterProvider(name string, provider DatabaseProvider) error

RegisterProvider registers a database provider

type DatabaseProvider

type DatabaseProvider interface {
	Connect() error
	Disconnect() error
	GetDB() interface{}
}

DatabaseProvider defines the interface for database providers

type EntityGenerator

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

EntityGenerator watches schema files and generates entities

func NewEntityGenerator

func NewEntityGenerator() (*EntityGenerator, error)

NewEntityGenerator creates a new entity generator

func (*EntityGenerator) Start

func (g *EntityGenerator) Start() error

Start starts watching for schema changes

func (*EntityGenerator) Stop

func (g *EntityGenerator) Stop()

Stop stops watching for schema changes

type Event

type Event interface {
	GetName() string
	GetTimestamp() time.Time
}

Event represents an event that can be published

type EventBus

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

EventBus manages event subscriptions and publishing

func NewEventBus

func NewEventBus() *EventBus

NewEventBus creates a new event bus

func (*EventBus) Clear

func (b *EventBus) Clear(eventName string) error

Clear removes all handlers for an event

func (*EventBus) ClearAll

func (b *EventBus) ClearAll()

ClearAll removes all handlers

func (*EventBus) Publish

func (b *EventBus) Publish(event Event) error

Publish publishes an event to all subscribers

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(eventName string, handler EventHandler) error

Subscribe subscribes to an event

func (*EventBus) Unsubscribe

func (b *EventBus) Unsubscribe(eventName string, handler EventHandler) error

Unsubscribe removes a handler from an event

type EventHandler

type EventHandler func(Event) error

EventHandler is a function that handles an event

type Guard

type Guard interface {
	CanActivate(c *fiber.Ctx) error
}

type Interceptor

type Interceptor func(*fiber.Ctx, fiber.Handler) error

Interceptor is a function that can intercept requests

func AuthInterceptor

func AuthInterceptor() Interceptor

AuthInterceptor example interceptor

func ErrorInterceptor

func ErrorInterceptor() Interceptor

ErrorInterceptor example interceptor

func LoggingInterceptor

func LoggingInterceptor() Interceptor

LoggingInterceptor example interceptor

type InterceptorMeta

type InterceptorMeta struct {
	Path        string
	Interceptor Interceptor
}

InterceptorMeta stores interceptor metadata

func GetInterceptors

func GetInterceptors() []InterceptorMeta

GetInterceptors returns all registered interceptors

type InterceptorOptions

type InterceptorOptions struct {
	Path string
}

InterceptorOptions defines interceptor configuration

type JWTProvider

type JWTProvider struct {
	Secret string
}

JWTProvider implements JWT authentication

func NewJWTProvider

func NewJWTProvider(secret string) *JWTProvider

NewJWTProvider creates a new JWT provider

func (*JWTProvider) Authenticate

func (p *JWTProvider) Authenticate(ctx *fiber.Ctx) (interface{}, error)

Authenticate implements JWT authentication

type LogLevel

type LogLevel int

LogLevel represents the log level

const (
	Debug LogLevel = iota
	Info
	Warn
	Error
	Fatal
)

type Logger

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

Logger is a configurable logger

func NewLogger

func NewLogger(level LogLevel) *Logger

NewLogger creates a new logger

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

Error logs an error message

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...interface{})

Fatal logs a fatal message and exits

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

Info logs an info message

func (*Logger) SetOutput

func (l *Logger) SetOutput(output *log.Logger)

SetOutput sets the output destination

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

Warn logs a warning message

type MiddlewareChain

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

MiddlewareChain represents a chain of middleware functions

func Compose

func Compose(middlewares ...MiddlewareFunc) *MiddlewareChain

Compose creates a new middleware chain from multiple middleware functions

func NewMiddlewareChain

func NewMiddlewareChain() *MiddlewareChain

NewMiddlewareChain creates a new middleware chain

func (*MiddlewareChain) Then

func (c *MiddlewareChain) Then(handler fiber.Handler) fiber.Handler

Then executes the middleware chain

func (*MiddlewareChain) Use

func (c *MiddlewareChain) Use(middleware MiddlewareFunc)

Use adds a middleware to the chain

type MiddlewareFunc

type MiddlewareFunc func(*fiber.Ctx) error

MiddlewareFunc is a function that can be used as middleware

func CreateMiddleware

func CreateMiddleware(fn func(*fiber.Ctx) error) MiddlewareFunc

CreateMiddleware creates a new middleware function

type ModuleMeta

type ModuleMeta struct {
	Instance    interface{}
	Imports     []interface{}
	Controllers []interface{}
	Providers   []interface{}
	Exports     []interface{}
}

ModuleMeta stores module metadata

func GetModule

func GetModule(moduleType interface{}) (ModuleMeta, error)

GetModule returns a module by type

func GetModules

func GetModules() []ModuleMeta

GetModules returns all registered modules

type ModuleOptions

type ModuleOptions struct {
	Imports     []interface{}
	Controllers []interface{}
	Providers   []interface{}
	Exports     []interface{}
}

ModuleOptions defines module configuration

type MongoDBProvider

type MongoDBProvider struct {
	URI      string
	Database string
	// contains filtered or unexported fields
}

MongoDBProvider implements MongoDB database provider

func NewMongoDBProvider

func NewMongoDBProvider(uri, database string) *MongoDBProvider

NewMongoDBProvider creates a new MongoDB provider

func (*MongoDBProvider) Connect

func (p *MongoDBProvider) Connect() error

Connect implements MongoDB connection

func (*MongoDBProvider) Disconnect

func (p *MongoDBProvider) Disconnect() error

Disconnect implements MongoDB disconnection

func (*MongoDBProvider) GetCollection

func (p *MongoDBProvider) GetCollection(name string) *mongo.Collection

GetCollection returns a MongoDB collection

func (*MongoDBProvider) GetDB

func (p *MongoDBProvider) GetDB() interface{}

GetDB returns the MongoDB database instance

type MySQLProvider

type MySQLProvider struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
	// contains filtered or unexported fields
}

MySQLProvider implements MySQL database provider

func NewMySQLProvider

func NewMySQLProvider(host string, port int, user, password, database string) *MySQLProvider

NewMySQLProvider creates a new MySQL provider

func (*MySQLProvider) Connect

func (p *MySQLProvider) Connect() error

Connect implements MySQL connection

func (*MySQLProvider) Disconnect

func (p *MySQLProvider) Disconnect() error

Disconnect implements MySQL disconnection

func (*MySQLProvider) GetDB

func (p *MySQLProvider) GetDB() *sql.DB

GetDB returns the database connection

type Permission

type Permission string

Permission represents a permission

type Pipe

type Pipe func(interface{}) (interface{}, error)

Pipe is a function that can transform or validate data

func CustomPipe

func CustomPipe(validate func(interface{}) error) Pipe

CustomPipe creates a custom pipe with a validation function

func DefaultPipe

func DefaultPipe(defaultValue interface{}) Pipe

DefaultPipe provides a default value if the input is nil

func LengthPipe

func LengthPipe(min, max int) Pipe

LengthPipe validates string or slice length

func ParseBoolPipe

func ParseBoolPipe() Pipe

ParseBoolPipe example pipe

func ParseIntPipe

func ParseIntPipe() Pipe

ParseIntPipe example pipe

func RangePipe

func RangePipe(min, max float64) Pipe

RangePipe validates that a number is within a range

func RegexPipe

func RegexPipe(pattern string) Pipe

RegexPipe validates a string against a regular expression

func TrimPipe

func TrimPipe() Pipe

TrimPipe example pipe

func ValidationPipe

func ValidationPipe() Pipe

ValidationPipe example pipe

type PipeMeta

type PipeMeta struct {
	Type reflect.Type
	Pipe Pipe
}

PipeMeta stores pipe metadata

func GetPipes

func GetPipes() []PipeMeta

GetPipes returns all registered pipes

type PipeOptions

type PipeOptions struct {
	Type reflect.Type
}

PipeOptions defines pipe configuration

type Plugin

type Plugin interface {
	// Register is called when the plugin is initialized
	Register(app *App) error
	// Start is called when the plugin is started
	Start() error
	// Stop is called when the plugin is stopped
	Stop() error
	// GetName returns the name of the plugin
	GetName() string
	// GetVersion returns the version of the plugin
	GetVersion() string
	// GetState returns the current state of the plugin
	GetState() PluginState
}

Plugin interface defines the contract for all plugins

type PluginRegistry

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

PluginRegistry manages all registered plugins

func NewPluginRegistry

func NewPluginRegistry() *PluginRegistry

NewPluginRegistry creates a new plugin registry

func (*PluginRegistry) GetPlugin

func (r *PluginRegistry) GetPlugin(name string) (Plugin, error)

GetPlugin retrieves a plugin by name

func (*PluginRegistry) InitializePlugins

func (r *PluginRegistry) InitializePlugins(app *App) error

InitializePlugins initializes all registered plugins

func (*PluginRegistry) RegisterPlugin

func (r *PluginRegistry) RegisterPlugin(plugin Plugin) error

RegisterPlugin adds a new plugin to the registry

func (*PluginRegistry) StartPlugins

func (r *PluginRegistry) StartPlugins() error

StartPlugins starts all registered plugins

func (*PluginRegistry) StopPlugins

func (r *PluginRegistry) StopPlugins() error

StopPlugins stops all registered plugins

type PluginState

type PluginState int

PluginState represents the state of a plugin

const (
	PluginStateUninitialized PluginState = iota
	PluginStateInitialized
	PluginStateStarted
	PluginStateStopped
)

type PostgreSQLProvider

type PostgreSQLProvider struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
	// contains filtered or unexported fields
}

PostgreSQLProvider implements PostgreSQL database provider

func NewPostgreSQLProvider

func NewPostgreSQLProvider(host string, port int, user, password, database string) *PostgreSQLProvider

NewPostgreSQLProvider creates a new PostgreSQL provider

func (*PostgreSQLProvider) Connect

func (p *PostgreSQLProvider) Connect() error

Connect implements PostgreSQL connection

func (*PostgreSQLProvider) Disconnect

func (p *PostgreSQLProvider) Disconnect() error

Disconnect implements PostgreSQL disconnection

func (*PostgreSQLProvider) GetDB

func (p *PostgreSQLProvider) GetDB() *sql.DB

GetDB returns the database connection

type Role

type Role string

Role represents a user role

const (
	RoleAdmin Role = "admin"
	RoleUser  Role = "user"
)

type RouteMeta

type RouteMeta struct {
	Path    string
	Method  string
	Handler string
	Guards  []Guard
	Pipes   []PipeMeta
}

RouteMeta stores route metadata

type RouteOptions

type RouteOptions struct {
	Path   string
	Method string
}

RouteOptions defines route configuration

Jump to

Keyboard shortcuts

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