app #
fn default_config #
fn default_config() Config
default_config returns default configuration
fn load_config #
fn load_config(path string) !Config
load_config loads configuration from a TOML file
fn new #
fn new(name string) &App
new creates a new Varel application
struct App #
struct App {
pub mut:
name string
config Config
router &router.Router
renderer &templates.Renderer = unsafe { nil } // Template renderer (optional)
db_config vareldb.Config // Database config (passed to workers)
has_db bool // Flag: database configured
}
App is the main application structure
fn (App) config_file #
fn (mut a App) config_file(path string) &App
config_file loads configuration from a TOML file
fn (App) use_middleware #
fn (mut a App) use_middleware(mw middleware.IMiddleware) &App
use_middleware adds struct-based middleware to the application (v0.2.0+) This is the new preferred way to register middleware
fn (App) templates #
fn (mut a App) templates(config templates.RendererConfig) &App
templates configures the template renderer
fn (App) database #
fn (mut a App) database(config vareldb.Config) &App
database stores database configuration for lazy initialization The actual connection pool will be created when the server starts (in listen())
fn (App) get #
fn (mut a App) get(path string, handler http.HandlerFunc) !
HTTP method handlers
fn (App) post #
fn (mut a App) post(path string, handler http.HandlerFunc) !
fn (App) put #
fn (mut a App) put(path string, handler http.HandlerFunc) !
fn (App) delete #
fn (mut a App) delete(path string, handler http.HandlerFunc) !
fn (App) patch #
fn (mut a App) patch(path string, handler http.HandlerFunc) !
fn (App) head #
fn (mut a App) head(path string, handler http.HandlerFunc) !
fn (App) options #
fn (mut a App) options(path string, handler http.HandlerFunc) !
fn (App) group #
fn (mut a App) group(prefix string) &router.RouterGroup
group creates a new route group with path prefix
fn (App) static #
fn (mut a App) static(url_path string, root string) !
static serves static files from a directory
fn (App) listen #
fn (mut a App) listen(addr string)
listen starts the single-process HTTP server using picoev
fn (App) close #
fn (mut a App) close()
close gracefully shuts down the server
Note: Shutdown is handled by signal handlers in master process
struct AppConfig #
struct AppConfig {
pub mut:
name string = 'Varel App'
env string = 'development' // development, production, test
}
struct Config #
struct Config {
pub mut:
app AppConfig
server ServerConfig
logging LoggingConfig
static StaticConfig
}
Config holds all application configuration
struct LoggingConfig #
struct LoggingConfig {
pub mut:
level string = 'info' // debug, info, warn, error
format string = 'dev' // dev, json
}
struct ServerConfig #
struct ServerConfig {
pub mut:
addr string = ':8080'
read_timeout_secs int = 30 // Timeout in seconds (TOML-compatible)
write_timeout_secs int = 30 // Timeout in seconds (TOML-compatible)
max_read int = 5_5000000 // Max request size (5MB default, for file uploads)
max_write int = 116384 // Max response size (16KB default)
}
fn (ServerConfig) read_timeout #
fn (sc ServerConfig) read_timeout() time.Duration
Helper methods for time.Duration conversion
fn (ServerConfig) write_timeout #
fn (sc ServerConfig) write_timeout() time.Duration
struct StaticConfig #
struct StaticConfig {
pub mut:
enabled bool = true
path string = '/assets'
root string = './public'
max_age int = 3600
enable_etag bool = true
enable_index bool = true
}