Conflex (pronounced /ˈkɒnflɛks/) is a powerful and versatile configuration management package for Go that simplifies handling application settings across different environments and formats.
- Simple and intuitive API for easy integration
- Support for multiple configuration formats (e.g., JSON, YAML)
- Support for multiple configuration sources (e.g., files, environment variables)
- Support for multiple configuration dumping destinations (files)
- Smart configuration merging with override policies
- Remote configuration sources (e.g., Consul)
- Automatic environment variable binding with customizable prefixes
- Deep nested configuration support with dot notation
- Type-safe configuration access with default values
- Comprehensive error handling and logging
- Performance optimized for large configurations
go get go.companyinfo.dev/conflex
package main
import (
"go.companyinfo.dev/conflex"
"go.companyinfo.dev/conflex/codec"
"context"
"log"
)
func main() {
cfg, err := conflex.New(
conflex.WithFileSource("config.yaml", codec.TypeYAML),
conflex.WithFileSource("config.json", codec.TypeJSON),
// By default, it will use the Consul API client and
// lookup CONSUL_HTTP_ADDR and CONSUL_HTTP_TOKEN environment variables
conflex.WithConsulSource("staging/service", codec.TypeJSON),
)
if err != nil {
log.Fatalf("failed to create configuration: %v", err)
}
err = cfg.Load(context.Background())
if err != nil {
log.Fatalf("failed to load configuration: %v", err)
}
// Access configuration values
port := cfg.GetInt("server.port")
host := cfg.GetString("server.host")
log.Printf("Server is running on %s:%d", host, port)
}
- Support for more configuration formats:
- TOML (Tom's Obvious, Minimal Language)
- HCL (HashiCorp Configuration Language)
- INI (INI Configuration)
- Support for more configuration sources:
- Command line flags (e.g.,
--host=localhost
) - Vault (HashiCorp Vault)
- Etcd
- Zookeeper (Apache ZooKeeper)
- Redis/Valkey (Redis Key-Value Store)
- Memcached (Memcached Key-Value Store)
- Command line flags (e.g.,
- Support for hot reloading of configuration changes
- Support for decryption of sensitive configuration values (e.g., SOPS)
- Support for configuration validation with JSON Schema
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement
) - Make your changes
- Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/improvement
) - Create a Pull Request
Please make sure to:
- Follow the existing code style
- Add tests if applicable
- Update documentation as needed
- Include a clear description of your changes in the PR
Copyright © 2025 Company.info
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.