Skip to main content
Version: 2.8.x(Latest)

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 - 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.