A flexible and comfortable, URI-based configuration management library for Go with real-time updates.
- Multi-protocol: File, HTTP, WebSocket, Redis, Kubernetes
- Multi-format: JSON, YAML, INI, TOML, XML
- Real-time updates: Subscribe to configuration changes
- Type-safe: Strong struct mapping with mapstructure
- Extensible: Plugin-based architecture
- Production-ready: TLS, retries, connection pooling
package main
import (
"fmt"
"log"
"github.com/sower-proxy/feconf"
_ "github.com/sower-proxy/feconf/decoder/json"
_ "github.com/sower-proxy/feconf/reader/file"
)
type Config struct {
Host string `json:"host"`
Port int `json:"port"`
}
func main() {
loader := feconf.New[Config]("file://./config.json")
defer loader.Close()
config, err := loader.Load()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Server: %s:%d\n", config.Host, config.Port)
}// File system
loader := feconf.New[Config]("file:///path/to/config.yaml")
// HTTP/HTTPS
loader := feconf.New[Config]("https://api.example.com/config.json")
// Redis
loader := feconf.New[Config]("redis://localhost:6379/config-key")
// WebSocket
loader := feconf.New[Config]("wss://realtime.example.com/config")
// Kubernetes
loader := feconf.New[Config]("k8s://configmap/default/app-config")- JSON:
.jsonorcontent-type=application/json - YAML:
.yaml,.ymlorcontent-type=application/yaml - INI:
.iniorcontent-type=text/ini - TOML:
.tomlorcontent-type=application/toml - XML:
.xmlorcontent-type=application/xml
eventChan, _ := loader.Subscribe()
for event := range eventChan {
if event.IsValid() {
fmt.Printf("Config updated: %v\n", event.Config)
}
}// Read from -config flag with fallback
loader := feconf.NewWithFlags[Config]("file://./default-config.json")The library follows a modular plugin-based architecture:
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Application │ │ Configuration │ │ Decoder │
│ │───▶│ Loader (feconf)│───▶│ (json/yaml/ │
│ Your Code │ │ │ │ ini/etc) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐
│ Reader │
│ (file/http/ │
│ redis/ws) │
└──────────────────┘
See the examples/ directory for complete working examples:
file-json/- Basic file-based configurationhttp-yaml/- HTTP with authenticationredis-ini/- Redis configurationflags/- Command-line flag integrationws-xml/- WebSocket real-time updatesk8s-yaml/- Kubernetes ConfigMap/Secret
Run examples:
cd examples/file-json && go run .
cd examples/http-yaml && go run .loader := feconf.New[Config](uri)
// Custom parser settings
loader.ParserConf.TagName = "config"
loader.ParserConf.ErrorUnused = true
// Custom decode hooks
loader.ParserConf.DecodeHook = mapstructure.ComposeDecodeHookFunc(
feconf.HookFuncDefault(),
feconf.HookFuncEnvRender(),
feconf.HookFuncStringToBool(),
)Common parameters:
content-type- Override format detectiontimeout- Request/operation timeoutretry_attempts- Number of retries
Protocol-specific parameters available for HTTP, Redis, and WebSocket connections.
go get github.com/sower-proxy/feconfMozilla Public License 2.0 - See LICENSE for details.