runtime

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppGetMySQL added in v0.1.1

func AppGetMySQL[T any](a *App, name string, tableName string) (*db.MySQLTable[T], error)

func AppGetPool added in v0.1.1

func AppGetPool[T any](a *App, name string, tableName string) (*db.Table[T], error)

func AppGetTurso added in v0.1.1

func AppGetTurso[T any](a *App, name string, tableName string) (*db.TursoTable[T], error)

Types

type App added in v0.1.1

type App struct {
	DB   map[string]any
	NATS map[string]*events.Conn
	// contains filtered or unexported fields
}

func NewApp added in v0.1.1

func NewApp(configPath string) (*App, error)

func (*App) AddDB added in v0.1.1

func (a *App) AddDB(ctx context.Context, name, driver, url string) error

func (*App) Run added in v0.1.1

func (a *App) Run() error

func (*App) WithCustomRoutes added in v0.1.1

func (a *App) WithCustomRoutes(fn func(app *fiber.App)) *App

type AuthConfig added in v0.1.1

type AuthConfig struct {
	Secret      string `json:"secret"`
	PrevSecret  string `json:"prev_secret,optional"`
	TokenLookup string `json:"token_lookup,default=header:Authorization"`
	ContextKey  string `json:"context_key,default=claims"`
}

type CORSConf

type CORSConf struct {
	Origins     []string `json:"origins,optional"`
	Methods     []string `json:"methods,optional"`
	Headers     []string `json:"headers,optional"`
	Credentials bool     `json:"credentials,optional"`
	MaxAge      int      `json:"max_age,default=300"`
}

type ConsumerDef added in v0.1.1

type ConsumerDef struct {
	Stream        string   `json:"stream"`
	Subject       string   `json:"subject,optional"`
	Durable       string   `json:"durable"`
	QueueGroup    string   `json:"queue_group,optional"`
	Handler       string   `json:"handler"`
	DeliverPolicy string   `json:"deliver_policy,default=all"`
	MaxDeliver    int      `json:"max_deliver,default=5"`
	AckWait       string   `json:"ack_wait,default=30s"`
	BackOff       []string `json:"backoff,optional"`
	PullBatch     int      `json:"pull_batch,default=10"`
	PullMaxWait   string   `json:"pull_max_wait,default=5s"`
	NakDelay      string   `json:"nak_delay,default=5s"`
}

type ContentSecurityConf added in v0.1.1

type ContentSecurityConf struct {
	Enabled   bool   `json:"enabled"`
	Strict    bool   `json:"strict,optional"`
	PublicKey string `json:"public_key,optional"`
}

type CryptionConf added in v0.1.1

type CryptionConf struct {
	Enabled bool   `json:"enabled"`
	Key     string `json:"key,optional"`
}

type DBConfig

type DBConfig struct {
	Name     string     `json:"name,optional"`
	Driver   string     `json:"driver,optional"`
	URL      string     `json:"url"`
	Table    string     `json:"table,optional"`
	Resource string     `json:"resource,optional"`
	Pool     PoolConfig `json:"pool,optional"`
}

func (DBConfig) DriverDefaults added in v0.1.1

func (d DBConfig) DriverDefaults()

type DefaultHooks

type DefaultHooks[T any] struct{}

func (DefaultHooks[T]) AfterCreate

func (DefaultHooks[T]) AfterCreate(ctx context.Context, entity *T) error

func (DefaultHooks[T]) AfterDelete

func (DefaultHooks[T]) AfterDelete(ctx context.Context, id any) error

func (DefaultHooks[T]) AfterUpdate

func (DefaultHooks[T]) AfterUpdate(ctx context.Context, entity *T) error

func (DefaultHooks[T]) BeforeCreate

func (DefaultHooks[T]) BeforeCreate(ctx context.Context, req T) (T, error)

func (DefaultHooks[T]) BeforeDelete

func (DefaultHooks[T]) BeforeDelete(ctx context.Context, id any) error

func (DefaultHooks[T]) BeforeUpdate

func (DefaultHooks[T]) BeforeUpdate(ctx context.Context, id any, patch map[string]any) (map[string]any, error)

type EndpointConf added in v0.1.1

type EndpointConf struct {
	List ListConfig `json:"list,optional"`
}

type FilterDef added in v0.1.1

type FilterDef struct {
	Column string `json:"column"`
	Type   string `json:"type"`
}

type GatewayConf added in v0.1.1

type GatewayConf struct {
	Enabled   bool          `json:"enabled"`
	Port      int           `json:"port,optional"`
	Upstreams []UpstreamDef `json:"upstreams,optional"`
}

type Hooks added in v0.1.1

type Hooks[T any] interface {
	BeforeCreate(ctx context.Context, req T) (T, error)
	AfterCreate(ctx context.Context, entity *T) error
	BeforeUpdate(ctx context.Context, id any, patch map[string]any) (map[string]any, error)
	AfterUpdate(ctx context.Context, entity *T) error
	BeforeDelete(ctx context.Context, id any) error
	AfterDelete(ctx context.Context, id any) error
}

type ListConfig added in v0.1.1

type ListConfig struct {
	PageSize   int         `json:"page_size,default=10"`
	MaxPage    int         `json:"max_page_size,default=100"`
	Sortable   []string    `json:"sortable,optional"`
	Filterable []FilterDef `json:"filterable,optional"`
}

func (ListConfig) EffectivePageSize added in v0.1.1

func (l ListConfig) EffectivePageSize(size int) int

func (ListConfig) IsFilterable added in v0.1.1

func (l ListConfig) IsFilterable(col string) bool

func (ListConfig) IsSortable added in v0.1.1

func (l ListConfig) IsSortable(col string) bool

type NATSConfig added in v0.1.1

type NATSConfig struct {
	Name          string        `json:"name,optional"`
	URL           string        `json:"url"`
	MaxReconnects int           `json:"max_reconnects,default=10"`
	ReconnectWait string        `json:"reconnect_wait,default=2s"`
	Timeout       string        `json:"timeout,default=5s"`
	RetryOnFail   bool          `json:"retry_on_fail,default=true"`
	Streams       []StreamDef   `json:"streams,optional"`
	Consumers     []ConsumerDef `json:"consumers,optional"`
	Producers     []ProducerDef `json:"producers,optional"`
}

type OpenAPIConf

type OpenAPIConf struct {
	Version  string `json:"version,default=1.0.0"`
	SpecPath string `json:"spec_path,default=/openapi.json"`
	DocsPath string `json:"docs_path,default=/docs"`
	Theme    string `json:"theme,default=moon"`
	DarkMode bool   `json:"dark_mode,default=true"`
}

type PaginatedResponse

type PaginatedResponse struct {
	Data  any   `json:"data"`
	Total int64 `json:"total"`
	Page  int   `json:"page"`
	Size  int   `json:"size"`
}

type PoolConfig added in v0.1.1

type PoolConfig struct {
	MaxConns          int32  `json:"max_conns,default=10"`
	MinConns          int32  `json:"min_conns,default=2"`
	MaxConnLifetime   string `json:"max_conn_lifetime,optional"`
	MaxConnIdleTime   string `json:"max_conn_idle_time,optional"`
	HealthCheckPeriod string `json:"health_check_period,default=1m"`
	ReservedConns     int32  `json:"reserved_conns,default=10"`
}

type ProducerDef added in v0.1.1

type ProducerDef struct {
	Stream  string   `json:"stream"`
	Subject string   `json:"subject,optional"`
	After   []string `json:"after,optional"`
}

type RealtimeConfig added in v0.1.1

type RealtimeConfig struct {
	SSE       []SSEDef       `json:"sse,optional"`
	WebSocket []WebSocketDef `json:"websocket,optional"`
}

type RedisConfig added in v0.1.1

type RedisConfig struct {
	Name          string `json:"name"`
	Addr          string `json:"addr"`
	Pass          string `json:"pass,optional"`
	DB            int    `json:"db,optional"`
	PoolSize      int    `json:"pool_size,default=10"`
	TLS           bool   `json:"tls,optional"`
	TLSSkipVerify bool   `json:"tls_skip_verify,default=true"`
}

type RouteConf added in v0.1.1

type RouteConf struct {
	Path       string   `json:"path"`
	Middleware []string `json:"middleware"`
}

type RouteMap added in v0.1.1

type RouteMap struct {
	Method string `json:"method"`
	Path   string `json:"path"`
}

type SSEDef added in v0.1.1

type SSEDef struct {
	Path    string `json:"path"`
	Handler string `json:"handler"`
	Auth    bool   `json:"auth,optional"`
}

type SSEHandler

type SSEHandler func(ctx context.Context, send func(data string)) error

type SecurityConf added in v0.1.1

type SecurityConf struct {
	ContentSecurity *ContentSecurityConf `json:"content_security,optional"`
	Cryption        *CryptionConf        `json:"cryption,optional"`
}

type ServerConf

type ServerConf struct {
	Static          []StaticDef `json:"static,optional"`
	Host            string      `json:"host,default=0.0.0.0"`
	Prefork         bool        `json:"prefork,optional"`
	BodyLimit       int         `json:"body_limit,default=4194304"`
	Timeout         string      `json:"timeout,default=30s"`
	MaxConns        int         `json:"max_conns,default=1000"`
	MaxBytes        int         `json:"max_bytes,default=4194304"`
	MetricsPath     string      `json:"metrics_path,default=/metrics"`
	HealthPath      string      `json:"health_path,default=/health"`
	ShutdownTimeout string      `json:"shutdown_timeout,default=10s"`
	RecoverStack    bool        `json:"recover_stack,default=true"`
	APIPrefix       string      `json:"api_prefix,default=/api/v1"`
	CORS            *CORSConf   `json:"cors,optional"`
	Routes          []RouteConf `json:"routes,optional"`
}

type Service

type Service[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](configPath string) (*Service[T], error)

func (*Service[T]) App

func (s *Service[T]) App() *fiber.App

func (*Service[T]) BuildOpenAPI added in v0.1.1

func (s *Service[T]) BuildOpenAPI() (*openapi3.T, error)

func (*Service[T]) Consume added in v0.1.1

func (s *Service[T]) Consume(stream string, durable string, handler func(ctx context.Context, data []byte) (events.AckAction, error)) error

func (*Service[T]) NATS

func (s *Service[T]) NATS() *events.Conn

func (*Service[T]) Pool

func (s *Service[T]) Pool() *pgxpool.Pool

func (*Service[T]) Run

func (s *Service[T]) Run() error

func (*Service[T]) RunWithContext

func (s *Service[T]) RunWithContext(ctx context.Context) error

func (*Service[T]) Table added in v0.1.1

func (s *Service[T]) Table() *db.Table[T]

func (*Service[T]) WithCustomRoutes added in v0.1.1

func (s *Service[T]) WithCustomRoutes(fn func(app *fiber.App)) *Service[T]

func (*Service[T]) WithHandlers

func (s *Service[T]) WithHandlers(h map[string]func(ctx context.Context, data []byte) (events.AckAction, error)) *Service[T]

func (*Service[T]) WithHooks

func (s *Service[T]) WithHooks(hooks Hooks[T]) *Service[T]

func (*Service[T]) WithSSEHandlers added in v0.1.1

func (s *Service[T]) WithSSEHandlers(h map[string]SSEHandler) *Service[T]

func (*Service[T]) WithWSHandlers added in v0.1.1

func (s *Service[T]) WithWSHandlers(h map[string]WSHandler) *Service[T]

type ServiceConfig

type ServiceConfig struct {
	Name      string         `json:"name"`
	Port      int            `json:"port,default=8080"`
	Health    bool           `json:"health,optional"`
	DB        DBConfig       `json:"database,optional"`
	NATS      NATSConfig     `json:"nats,optional"`
	Auth      AuthConfig     `json:"auth,optional"`
	Endpoints EndpointConf   `json:"endpoints,optional"`
	Realtime  RealtimeConfig `json:"realtime,optional"`
	Server    ServerConf     `json:"server,optional"`
	Telemetry TelemetryConf  `json:"telemetry,optional"`
	Security  SecurityConf   `json:"security,optional"`
	Gateway   GatewayConf    `json:"gateway,optional"`
	OpenAPI   OpenAPIConf    `json:"openapi,optional"`

	MultiDB    []DBConfig    `json:"databases,optional"`
	MultiNATS  []NATSConfig  `json:"nats_list,optional"`
	MultiRedis []RedisConfig `json:"redis,optional"`
	Services   []ServiceDef  `json:"services,optional"`
}

func LoadConfig

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

func (*ServiceConfig) Validate added in v0.1.1

func (c *ServiceConfig) Validate() error

type ServiceDef added in v0.1.1

type ServiceDef struct {
	Name    string `json:"name"`
	Model   string `json:"model"`
	Table   string `json:"table"`
	DBName  string `json:"db"`
	NATSRef string `json:"nats,optional"`
}

type StaticDef

type StaticDef struct {
	Prefix string `json:"prefix"`
	Dir    string `json:"dir"`
}

type StreamDef

type StreamDef struct {
	Name        string `json:"name"`
	MaxAge      string `json:"max_age,optional"`
	MaxBytes    int64  `json:"max_bytes,optional"`
	Storage     string `json:"storage,default=file"`
	Compression string `json:"compression,default=s2"`
}

type TelemetryConf added in v0.1.1

type TelemetryConf struct {
	Enabled  bool    `json:"enabled"`
	Name     string  `json:"name,optional"`
	Endpoint string  `json:"endpoint,optional"`
	Sampler  float64 `json:"sampler,optional"`
	Batcher  string  `json:"batcher,default=otlpgrpc"`
}

type UpstreamDef added in v0.1.1

type UpstreamDef struct {
	Name     string     `json:"name"`
	Target   string     `json:"target"`
	Mappings []RouteMap `json:"mappings,optional"`
}

type WSHandler

type WSHandler func(ctx context.Context, conn *websocket.Conn) error

type WebSocketDef added in v0.1.1

type WebSocketDef struct {
	Path    string `json:"path"`
	Handler string `json:"handler"`
	Auth    bool   `json:"auth,optional"`
}

Jump to

Keyboard shortcuts

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