Polaris
Configuration Center Example
Code Source: https://github.com/gogf/examples/tree/main/config/polaris
Description
This directory contains an example demonstrating how to integrate Polaris
configuration center with GoFrame
applications. It shows:
-
Polaris
Client ConfigurationPolaris
client setup and initialization- Configuration adapter implementation
- Error handling and logging
-
Configuration Management
- Configuration loading and parsing
- Dynamic configuration updates
- Configuration value retrieval
Directory Structure
.
├── boot/ # Bootstrap configuration
│ └── boot.go # Polaris client initialization
├── main.go # Main application entry
├── testdata/ # Test configuration files
├── go.mod # Go module file
└── go.sum # Go module checksums
Requirements
- Go 1.22 or higher
- Git
- GoFrame
- GoFrame Polaris Config
- Polaris Server
Features
The example showcases the following features:
-
Polaris
Integration- Client configuration
- Server connection management
- Configuration namespace
- Error handling
-
Configuration Management
- Configuration loading
- Value retrieval
- Type conversion
- Default values
-
Dynamic Updates
- Configuration watching
- Change notification
- Hot reload support
Configuration
Polaris
Server
-
Server Configuration:
- Default port: 8090
- Default address: localhost
- Default protocol:
gRPC
-
Authentication:
- Namespace isolation
- Group level access control
- Access token support
Client Configuration
-
Basic Settings:
- Namespace
- File group
- File name
- Configuration path
- Log directory
-
Advanced Options:
- Watch mode
- Retry settings
- Cache management
- Logging configuration
Usage
-
Start
Polaris
Server:# Start Polaris server using Docker
docker run -d --name polaris \
-p 8090:8090 -p 8091:8091 \
polarismesh/polaris-server -
Configure
Polaris
:- Access
Polaris
console at http://localhost:8090 - Create configuration items
- Set up access control
- Access
-
Run Example:
go run main.go
Implementation Details
-
Client Setup (
boot/boot.go
):- Namespace configuration
- File group and name setup
- Configuration path setup
- Log directory configuration
- Watch mode enablement
-
Configuration Access (
main.go
):- Configuration availability check
- Bulk configuration retrieval
- Single value access
- Error handling
Notes
- The example uses Polaris's configuration center features
- Configuration changes in Polaris are automatically reflected when watch mode is enabled
- Configuration is organized by namespace and file group
- Log files are stored in the specified log directory
- Configuration path points to the Polaris server configuration file
- Watch mode enables dynamic configuration updates