config

package module
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

apollo-golang

Apollo client for golang

支持的环境变量:

APOLLO_META_SERVER_URL
APOLLO_ACCESSKEY_SECRET
TENANT_NAMESPACE

demo
package main

import config "github.com/yunkeCN/apollo-golang"

type MysqlSettingS struct {
	Host             string
	Port             string
	UserName         string
	Password         string
	DBName           string
	Charset          string
	MaxConnLifetime  int
	MaxIdleConnCount int
	MaxOpenConnCount int
}

var settings = &MysqlSettingS{}

// 加载配置
func loadConfig() error {
	if err := config.MapConfig("Mysql", settings, true); err != nil {
		return err
	}

	return nil
}

func main() {
	
	// 配置应用名称和加载配置的回调
	c := &config.ApolloConfig{
		AppID:      "mars-base",
		LoadConfig: loadConfig,
	}
	
	// 启动服务
	err := config.NewApolloService(c)

	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	NAMESPACE_APP = "application"
)

Variables

This section is empty.

Functions

func MapConfig

func MapConfig(section string, v interface{}, isListenChange bool) error

MapConfig loads config to struct v.

func NewApolloService

func NewApolloService(conf *ApolloConfig) error

Types

type ApolloConfig

type ApolloConfig struct {
	AppID      string
	LoadConfig func() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL