This package provides configuration structures and validation for the trellis framework.
The configuration package defines all configuration structures used by the framework, including service configuration, logger settings, middleware configurations (rate limiting, circuit breaker, CORS, etc.), and more.
The main configuration structure is Config, which contains:
The framework automatically sets default values for configuration fields:
"http" if empty30s if not setlogrus.InfoLevel if not set"json" if empty"stderr" if emptyThe framework supports both YAML and JSON configuration files:
config.example.yamlconfig.example.jsonimport (
"trellis.tech/trellis/framework.v0/services"
)
service, err := services.New("config.yaml")
if err != nil {
log.Fatal(err)
}
import (
"github.com/sirupsen/logrus"
"trellis.tech/trellis/framework.v0/configs"
"trellis.tech/trellis/framework.v0/services"
)
cfg := &configs.Config{
ServiceType: configs.ServiceTypeHTTP,
ServiceConfig: configs.ServiceConfig{
Name: "my_service",
Address: ":8080",
Mode: "release",
},
LoggerConfig: configs.LoggerConfig{
Level: logrus.InfoLevel,
Formatter: "json",
DefaultWriter: "stderr",
},
}
// Defaults are automatically set during validation
service, err := services.NewWithConfig(cfg)
if err != nil {
log.Fatal(err)
}
Enable configuration hot reload to apply changes without restarting:
hot_reload:
enabled: true
config_file: "./config.yaml"
reload_signal: "SIGHUP"
validate_before_reload: true
debounce_interval: 1s
reloadable_sections: [] # empty = reload all reloadable sections
Non-reloadable fields are preserved automatically (e.g., service.address, service.name, service_type).
The framework validates configuration automatically:
^[a-zA-Z][a-zA-Z0-9_]+$You can manually set defaults before validation:
cfg := &configs.Config{
ServiceConfig: configs.ServiceConfig{
Name: "my_service",
},
}
// Set defaults manually
cfg.SetDefaults()
// Or let Validate() set them automatically
err := cfg.Validate()
service:
name: "my_service"
address: ":8080"
See config.example.yaml or config.example.json for a complete example with all available options.
See config.example.yaml or config.example.json for a complete configuration example with all available options.
The framework automatically validates configuration when creating a service:
^[a-zA-Z][a-zA-Z0-9_]+$service.name and service.addressValidate() before using configurationAll HTTP and gRPC middlewares/interceptors register Prometheus metrics via trellis.tech/trellis/framework.v0/utils/metrics.
This abstraction lets you swap the underlying prometheus.Registerer:
import (
\"github.com/prometheus/client_golang/prometheus\"
\"github.com/prometheus/client_golang/prometheus/prometheus\"
\"trellis.tech/trellis/framework.v0/utils/metrics\"
)
func main() {
reg := prometheus.NewRegistry()
metrics.SetRegisterer(reg) // must be called before constructing the service
// proceed to create services.NewWithConfig(...)
}
If you prefer the built-in /metrics endpoint, set:
service:
metrics:
metric_path: \"/metrics\"
Alternatively, expose your custom registry via promhttp.HandlerFor(reg, ...) on your own mux.