Documentation
¶
Index ¶
- Constants
- Variables
- func Asset(name string) string
- func Config() *config.Config
- func DB() *gorm.DB
- func FileServerHandler() http.Handler
- func FuncMap() template.FuncMap
- func GetTemplates() *template.Template
- func Handler(h HandlerFunc) http.HandlerFunc
- func HashPassword(password string) (string, error)
- func LoadTemplates(patterns ...string) error
- func Logger() *logger.Logger
- func NewMigrationBuilder() *database.MigrationBuilder
- func NotFoundHandler() http.HandlerFunc
- func ParseToken(tokenString string) (string, error)
- func RegisterMigration(m *database.Migration)
- func RegisterMigrations(ms ...*database.Migration)
- func Reload(patterns ...string) error
- func SetAssetsFS(fs embed.FS)
- func SetTemplates(tmpl *template.Template)
- func UseErrorHandler(h ErrorHandlerFunc)
- type AuthConfig
- type BaseModel
- type CRUDStore
- type CRUDStoreInterface
- type Credentials
- type DatabaseConfig
- type ErrSeverity
- type Error
- type ErrorBuilder
- type ErrorHandlerFunc
- type HandlerFunc
- type Kit
- type LogLevel
- type LoggerConfig
- type Middleware
- type Migration
- type Polymorphic
- type Router
- type Seeder
- type Server
- type Token
Constants ¶
HTTP method constants for route registration.
const ( LogTrace = config.LogTrace LogDebug = config.LogDebug LogInfo = config.LogInfo LogWarn = config.LogWarn LogError = config.LogError LogCritical = config.LogCritical )
Log level constants.
const ( ErrMinor = errors.ErrMinor ErrError = errors.ErrError ErrCritical = errors.ErrCritical )
Error severity constants.
const ( AssetsPath = public.AssetsPath PublicPath = public.PublicPath )
Public asset path constants.
Variables ¶
var ( // General errors ErrNotFound = errors.ErrNotFound ErrDecodeJSON = errors.ErrDecodeJSON ErrDecodeForm = errors.ErrDecodeForm // Database errors (most common) ErrDatabaseRead = errors.ErrDatabaseRead ErrDatabaseWrite = errors.ErrDatabaseWrite ErrDatabaseUpdate = errors.ErrDatabaseUpdate ErrDatabaseDelete = errors.ErrDatabaseDelete ErrDatabaseObjectNotFound = errors.ErrDatabaseObjectNotFound ErrDatabaseConn = errors.ErrDatabaseConn ErrDatabaseMigration = errors.ErrDatabaseMigration // Auth errors (most common) ErrAuthInvalidToken = errors.ErrAuthInvalidToken ErrAuthExpiredToken = errors.ErrAuthExpiredToken ErrAuthInvalidCredentials = errors.ErrAuthInvalidCredentials ErrInsufficientPermissions = errors.ErrInsufficientPermissions ErrAuthMissingHeader = errors.ErrAuthMissingHeader ErrHashPassword = errors.ErrHashPassword ErrGenerateToken = errors.ErrGenerateToken // API errors (most common) ErrAPIRequestPayload = errors.ErrAPIRequestPayload ErrAPIObjectNotFound = errors.ErrAPIObjectNotFound ErrAPIIDMismatch = errors.ErrAPIIDMismatch ErrAPIPathValue = errors.ErrAPIPathValue ErrAPIRequestContentType = errors.ErrAPIRequestContentType // Server errors ErrListenAndServe = errors.ErrListenAndServe ErrShutdownServer = errors.ErrShutdownServer )
Common predefined errors for typical CRUD applications. For specialized errors, import pkg/errors directly.
var AssetsFS = &public.AssetsFS
AssetsFS should be set by the user application using //go:embed.
Example in user's code:
//go:embed assets
var AssetsFS embed.FS
func init() {
twine.AssetsFS = AssetsFS
}
Functions ¶
func FileServerHandler ¶
FileServerHandler returns an HTTP handler for serving embedded static files.
func GetTemplates ¶
GetTemplates returns the current template instance.
func Handler ¶
func Handler(h HandlerFunc) http.HandlerFunc
Handler converts a Kit.HandlerFunc to an http.HandlerFunc.
func HashPassword ¶
HashPassword hashes a password using bcrypt.
func LoadTemplates ¶
LoadTemplates loads all templates from the given glob patterns.
func NewMigrationBuilder ¶
func NewMigrationBuilder() *database.MigrationBuilder
NewMigrationBuilder creates a new MigrationBuilder instance.
func NotFoundHandler ¶
func NotFoundHandler() http.HandlerFunc
NotFoundHandler returns a handler for 404 errors.
func ParseToken ¶
ParseToken validates and parses a JWT token, returning the user ID.
func RegisterMigration ¶
RegisterMigration adds a migration to the database.
func RegisterMigrations ¶
RegisterMigrations adds multiple migrations to the database.
func SetAssetsFS ¶
SetAssetsFS sets the embedded filesystem for static assets.
func SetTemplates ¶
SetTemplates allows users to set a custom template instance.
func UseErrorHandler ¶
func UseErrorHandler(h ErrorHandlerFunc)
UseErrorHandler sets a custom error handler for all Kit handlers.
Types ¶
type AuthConfig ¶
type AuthConfig = config.AuthConfig
AuthConfig holds authentication configuration.
type CRUDStoreInterface ¶
type CRUDStoreInterface[T any] = database.CRUDStoreInterface[T]
CRUDStoreInterface defines the interface for CRUD operations.
type Credentials ¶
type Credentials = auth.Credentials
Credentials holds user authentication credentials.
type DatabaseConfig ¶
type DatabaseConfig = config.DatabaseConfig
DatabaseConfig holds database connection settings.
type ErrSeverity ¶
type ErrSeverity = errors.ErrSeverity
ErrSeverity represents the severity level of an error.
type ErrorBuilder ¶
type ErrorBuilder = errors.ErrorBuilder
ErrorBuilder provides a fluent interface for building errors.
func NewErrorBuilder ¶
func NewErrorBuilder() *ErrorBuilder
NewErrorBuilder creates a new error builder for custom errors.
type ErrorHandlerFunc ¶
type ErrorHandlerFunc = kit.ErrorHandlerFunc
ErrorHandlerFunc is the signature for custom error handlers.
type HandlerFunc ¶
type HandlerFunc = kit.HandlerFunc
HandlerFunc is the signature for Twine handlers that return errors.
func ApplyMiddlewares ¶
func ApplyMiddlewares(h HandlerFunc, middlewares ...Middleware) HandlerFunc
ApplyMiddlewares chains multiple middlewares together.
type LoggerConfig ¶
type LoggerConfig = config.LoggerConfig
LoggerConfig holds logging configuration.
type Middleware ¶
type Middleware = middleware.Middleware
Middleware is the signature for middleware functions.
func Chain ¶
func Chain(middlewares ...Middleware) Middleware
Chain combines multiple middlewares into a single middleware. Useful for composing middlewares in layout files.
func JWTMiddleware ¶
func JWTMiddleware() Middleware
JWTMiddleware validates JWT tokens and auto-redirects on failure.
func LoggingMiddleware ¶
func LoggingMiddleware() Middleware
LoggingMiddleware logs incoming requests.
func TimeoutMiddleware ¶
func TimeoutMiddleware(d time.Duration) Middleware
TimeoutMiddleware adds a timeout to request processing.
type Polymorphic ¶
type Polymorphic = database.Polymorphic
Polymorphic provides fields for polymorphic relationships.