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

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:

  1. Polaris Client Configuration

    • Polaris client setup and initialization
    • Configuration adapter implementation
    • Error handling and logging
  2. 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

Features

The example showcases the following features:

  1. Polaris Integration

    • Client configuration
    • Server connection management
    • Configuration namespace
    • Error handling
  2. Configuration Management

    • Configuration loading
    • Value retrieval
    • Type conversion
    • Default values
  3. Dynamic Updates

    • Configuration watching
    • Change notification
    • Hot reload support

Configuration

Polaris Server

  1. Server Configuration:

    • Default port: 8090
    • Default address: localhost
    • Default protocol: gRPC
  2. Authentication:

    • Namespace isolation
    • Group level access control
    • Access token support

Client Configuration

  1. Basic Settings:

    • Namespace
    • File group
    • File name
    • Configuration path
    • Log directory
  2. Advanced Options:

    • Watch mode
    • Retry settings
    • Cache management
    • Logging configuration

Usage

  1. Start Polaris Server:

    # Start Polaris server using Docker
    docker run -d --name polaris \
    -p 8090:8090 -p 8091:8091 \
    polarismesh/polaris-server
  2. Configure Polaris:

  3. Run Example:

    go run main.go

Implementation Details

  1. Client Setup (boot/boot.go):

    • Namespace configuration
    • File group and name setup
    • Configuration path setup
    • Log directory configuration
    • Watch mode enablement
  2. 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