Nacos
Configuration Center Example
Description
This directory contains an example demonstrating how to integrate Nacos
configuration center with GoFrame
applications. It shows:
-
Nacos
Client ConfigurationNacos
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 # Nacos client initialization
├── main.go # Main application entry
├── go.mod # Go module file
└── go.sum # Go module checksums
Requirements
- Go 1.22 or higher
- Git
- GoFrame
- GoFrame Nacos Config
- Nacos Server
Features
The example showcases the following features:
-
Nacos
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
Nacos
Server
-
Server Configuration:
- Default port: 8848
- Default address: localhost
- Default protocol: HTTP
-
Authentication:
- Username/Password authentication
- Namespace isolation
- Group level access control
Client Configuration
-
Basic Settings:
- Server address and port
- Cache directory
- Log directory
- Data ID and Group
-
Advanced Options:
- Namespace customization
- Cache management
- Logging configuration
- Retry settings
Usage
-
Start
Nacos
Server:# Start Nacos server using Docker
docker run -d --name nacos \
-p 8848:8848 -p 9848:9848 \
-e MODE=standalone \
nacos/nacos-server:latest -
Configure
Nacos
:- Access
Nacos
console at http://localhost:8848/nacos - Default credentials: nacos/nacos
- Create configuration items
- Access
-
Run Example:
go run main.go