Introduction
GoFrame
's configuration management is implemented by the gcfg
component, and all methods of the gcfg
component are concurrent safe. The gcfg
component adopts an interface-based design and provides a file system-based interface implementation by default.
Usage:
import "github.com/gogf/gf/v2/os/gcfg"
Interface Documentation:
https://pkg.go.dev/github.com/gogf/gf/v2/os/gcfg
Features
The gcfg
component has the following notable features:
- Interface-based design, providing high flexibility and extensibility, with a default file system interface implementation
- Supports various common configuration file formats:
yaml/toml/json/xml/ini/properties
- Supports reading specified environment variables or command line arguments when configuration items do not exist
- Supports retrieval and reading of configuration files from the resource management component
- Supports automatic detection of hot update features for configuration files
- Supports hierarchical access to configuration items
- Supports a singleton management model
Precautions
The framework's configuration component supports a variety of common data formats, but the subsequent example code will be demonstrated using the yaml
data format. In use, feel free to use the data format of your choice without being restricted to the yaml
data format used in the official examples. For example, if the business project template provides a config.yaml
configuration file template (because the default template can only provide one), you can also directly modify it to config.toml
or config.ini
and other supported data formats, the configuration component can also automatically recognize and read based on the file name suffix.
Documents
📄️ Configuration - Object
Use the GoFrame framework for configuration management, acquiring configuration objects through the singleton pattern. With g.Cfg() and gcfg.Instance methods, it's easy to read global configurations like database connection info and template engine directory settings. Supports auto-searching and caching configuration files by file extension to enhance development efficiency.
📄️ Configuration - File
The gcfg component in the GoFrame framework supports multiple configuration file formats such as JSON, XML, YAML, etc., and offers flexible directory configuration and hierarchical access capabilities. It uses an interface-based design, allowing configuration items to be dynamically modified through environment variables and command line parameters. The unique caching mechanism and auto-detect update feature ensure configuration efficiency and real-time capability, making it an ideal choice for configuration management.
📄️ Configuration - Methods
Common methods in configuration management using the GoFrame framework, including how to obtain configuration data from environmental variables and command line, the Data method for acquiring and assembling configuration data, and the use of configuration adapters. Through example code, help developers better grasp the technical key points related to configuration management.
🗃️ Configuration - Interface
2 items
📄️ Configuration - YAML
Configuration management using YAML format in the GoFrame framework. YAML is a data serialization format that is easy for humans to read and write and supports data structures like objects, arrays, and scalars. The article also provides examples of conversion between YAML and JavaScript to help readers better understand the application and implementation of YAML format.
📄️ Configuration - TOML
The use of TOML format in the GoFrame framework, including its comparison with other file formats, basic syntax, numeric and BOOL value processing, date and time, arrays, tables, table arrays, etc., to help users better understand and apply TOML configuration management.