pkg

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFlashClearHistoryKeyPrefix = "flash_clear_history:"
View Source
const DefaultFlashErrKeyPrefix = "flash_err:"
View Source
const DefaultSessionKey = "session_id"
View Source
const DefaultSessionName = "session"

Variables

View Source
var (
	ExtensionNotPointerError = errors.New("given extension must be a pointer")
	CyclicDependencyError    = errors.New("cyclic extension dependency detected")
)
View Source
var DefaultIgnoreList = []string{"api", "swagger"}

DefaultIgnoreList is the default list of paths that will be ignored by the dev proxy

View Source
var DefaultInertiaRootTemplate []byte

Functions

func GetExtension

func GetExtension[T Extension](b *Bat) T

Types

type Bat

type Bat struct {
	Logger *Logger
	*echo.Echo

	// SkipPaths is a list of paths that should not be logged
	SkipPaths []string
	// contains filtered or unexported fields
}

func NewBat

func NewBat(logger *Logger, extensions ...Extension) (*Bat, error)

func (*Bat) NewContext

func (b *Bat) NewContext(req *http.Request, res http.ResponseWriter) echo.Context

func (*Bat) RegisterControllers

func (b *Bat) RegisterControllers(controllers ...Controller) error

func (*Bat) Start

func (b *Bat) Start(addr string) error

type BatContext

type BatContext struct {
	echo.Context
}

type BatOption

type BatOption func(*Bat) error

type Controller

type Controller interface {
	Register(app *Bat) error
	GetControllerName() string
}

type DatabaseExtension

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

func NewDatabaseExtension

func NewDatabaseExtension(db *sqlx.DB) *DatabaseExtension

func (*DatabaseExtension) GetDB

func (d *DatabaseExtension) GetDB() *sqlx.DB

func (*DatabaseExtension) Register

func (d *DatabaseExtension) Register(app *Bat) error

func (*DatabaseExtension) Requirements

func (d *DatabaseExtension) Requirements() []reflect.Type

type Extension

type Extension interface {
	Register(app *Bat) error
	Requirements() []reflect.Type
}

type FlashExtension

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

FlashExtension is an extension that provides error flash functionality

func NewFlashExtension

func NewFlashExtension(opts ...FlashExtensionOption) (*FlashExtension, error)

NewFlashExtension creates a new flash extension, it expects that the context contains a sessionID

func (*FlashExtension) FlashClearHistory

func (f *FlashExtension) FlashClearHistory(ctx context.Context) error

FlashClearHistory sets the flash clear history flag

func (*FlashExtension) FlashErrors

func (f *FlashExtension) FlashErrors(ctx context.Context, errors gonertia.ValidationErrors) error

FlashErrors adds the errors to the flash provider

func (*FlashExtension) GetErrors

GetErrors returns the errors from the flash provider

func (*FlashExtension) Register

func (f *FlashExtension) Register(app *Bat) error

Register registers the flash extension

func (*FlashExtension) Requirements

func (f *FlashExtension) Requirements() []reflect.Type

Requirements returns the requirements for the flash extension

func (*FlashExtension) ShouldClearHistory

func (f *FlashExtension) ShouldClearHistory(ctx context.Context) (bool, error)

ShouldClearHistory returns whether the history should be cleared

type FlashExtensionOption

type FlashExtensionOption func(*FlashExtension) error

FlashExtensionOption is a function that modifies the FlashExtension

func WithFlashClearHistoryKeyPrefix

func WithFlashClearHistoryKeyPrefix(prefix string) FlashExtensionOption

WithFlashClearHistoryKeyPrefix sets the flash clear history key prefix

func WithFlashErrKeyPrefix

func WithFlashErrKeyPrefix(prefix string) FlashExtensionOption

WithFlashErrKeyPrefix sets the flash error key prefix

type InertiaExtension

type InertiaExtension struct {
	// Inertia is the Inertia instance that will be used by the InertiaExtension
	Inertia *gonertia.Inertia
	// contains filtered or unexported fields
}

InertiaExtension is an extension that provides Inertia support to the application

func NewInertiaExtension

func NewInertiaExtension(distDirFS fs.FS, manifest []byte, isDev bool, opts ...InertiaExtensionOption) (*InertiaExtension, error)

NewInertiaExtension creates a new InertiaExtension

func (*InertiaExtension) Register

func (i *InertiaExtension) Register(app *Bat) error

Register registers the InertiaExtension

func (*InertiaExtension) Requirements

func (i *InertiaExtension) Requirements() []reflect.Type

Requirements returns the requirements for the InertiaExtension

type InertiaExtensionOption

type InertiaExtensionOption func(i *InertiaExtension) error

InertiaExtensionOption is a function that sets an option on the InertiaExtension

func WithDevServerURL

func WithDevServerURL(devServerURL string) InertiaExtensionOption

WithDevServerURL sets the dev server URL on the InertiaExtension

func WithFrontendPath

func WithFrontendPath(frontendPath string) InertiaExtensionOption

WithFrontendPath sets the frontend path on the InertiaExtension

func WithIgnoreList

func WithIgnoreList(ignoreList []string) InertiaExtensionOption

WithIgnoreList sets the ignore list on the InertiaExtension

func WithJSRuntime

func WithJSRuntime(jsRuntime string) InertiaExtensionOption

WithJSRuntime sets the JS runtime on the InertiaExtension

func WithRootTemplate

func WithRootTemplate(rootTemplate []byte) InertiaExtensionOption

WithRootTemplate sets the root template on the InertiaExtension

type Logger

type Logger struct {
	*slog.Logger
}

func NewLogger

func NewLogger(outputType LoggerOutputType, opts *slog.HandlerOptions, noColor bool) *Logger

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

type LoggerOutputType

type LoggerOutputType string
const (
	LoggerOutputTypeHuman LoggerOutputType = "human"
	LoggerOutputTypeJSON  LoggerOutputType = "json"
)

type SessionExtension

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

SessionExtension is an extension that provides session management

func NewSessionExtension

func NewSessionExtension(opts ...SessionExtensionOption) (*SessionExtension, error)

NewSessionExtension creates a new session extension

func (*SessionExtension) AttachSessionIDToRequestContext

func (s *SessionExtension) AttachSessionIDToRequestContext() echo.MiddlewareFunc

AttachSessionIDToRequestContext attaches the session ID to the request context

func (*SessionExtension) EnsureSession

func (s *SessionExtension) EnsureSession() echo.MiddlewareFunc

EnsureSession ensures that the session is created

func (*SessionExtension) GetSessionIDFromRequest

func (s *SessionExtension) GetSessionIDFromRequest(ctx context.Context) string

GetSessionIDFromRequest returns the session ID from the request context

func (*SessionExtension) Register

func (s *SessionExtension) Register(app *Bat) error

Register registers the session extension

func (*SessionExtension) Requirements

func (s *SessionExtension) Requirements() []reflect.Type

Requirements returns the requirements for the session extension

type SessionExtensionOption

type SessionExtensionOption func(*SessionExtension) error

SessionExtensionOption is a function that modifies the SessionExtension

func WithSessionKey

func WithSessionKey(key string) SessionExtensionOption

WithSessionKey sets the session key

func WithSessionName

func WithSessionName(name string) SessionExtensionOption

WithSessionName sets the session name

func WithSessionStore added in v0.4.0

func WithSessionStore(store sessions.Store) SessionExtensionOption

WithSessionStore sets the session store

type ValkeyExtension

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

ValkeyExtension is an extension that provides valkey functionality

func NewValkeyExtension

func NewValkeyExtension(client valkey.Client) *ValkeyExtension

NewValkeyExtension creates a new valkey extension

func (*ValkeyExtension) GetClient

func (v *ValkeyExtension) GetClient() valkey.Client

GetClient returns the valkey client

func (*ValkeyExtension) Register

func (v *ValkeyExtension) Register(app *Bat) error

Register registers the valkey extension

func (*ValkeyExtension) Requirements

func (v *ValkeyExtension) Requirements() []reflect.Type

Requirements returns the requirements of the valkey extension

Jump to

Keyboard shortcuts

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