confd

package module
v0.0.0-...-e997027 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: MIT Imports: 7 Imported by: 0

README

confd

Introduce

confd 是一个配置管理库,支持多种配置形式,多种渠道获取

Features

  • 支持多种数据来源(file, etcd,...)
  • 支持多种数据格式(json,yaml,...)
  • 支持watch配置变化
  • 支持配置的读管理

Start

测试结构体定义

type NestStruct struct {
    Nick  string  `json:"nick,omitempty" yaml:"nick,omitempty"`
    Score float64 `json:"score,omitempty" yaml:"score,omitempty"`
}

type TestStruct struct {
    Count int64      `json:"count,omitempty" yaml:"count,omitempty"`
    Str   string     `json:"str,omitempty" yaml:"str,omitempty"`
    Nest  NestStruct `json:"nest,omitempty" yaml:"nest,omitempty"`
}

使用方式


cnd := confd.NewConfd(confd.WithSchema("test1.yml"))

err := cnd.LoadConfig()
if err != nil{
// handler err
}

var val TestStruct
// read test1.yml to val
if err = cnd.Read(&val); err != nil{
// handler err
}

// read count to val.Count
if err = cnd.ReadSection("count", &val.Count); err != nil{
    // handler err
}

// read count to val.Count
if err = cnd.ReadSection("nest.nick", &val.Nest.Nick); err != nil{
// handler err
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SchemaErr = errors.New("schema error")
)

Functions

This section is empty.

Types

type Confd

type Confd struct {
	loader.ConfigLoader
	format.Marshaler
	config.Config
	// contains filtered or unexported fields
}

Confd conf manager

func NewConfd

func NewConfd(opts ...OptionFunc) *Confd

func (*Confd) LoadConfig

func (c *Confd) LoadConfig() (err error)

LoadConfig load config schema {source}:{format}:{key} source file, etcd,... format ymal, json,ini... key can read config information, eg ./xx.yml...

func (*Confd) WatchConfig

func (c *Confd) WatchConfig() (err error)

watch config change.

type OptionFunc

type OptionFunc func(*Options)

func WithConfer

func WithConfer(confer string) OptionFunc

func WithSchema

func WithSchema(schema string) OptionFunc

type Options

type Options struct {
	// contains filtered or unexported fields
}

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema schema {source}:{format}:{key} source file, etcd,... format ymal, json,ini... key can read config information, eg ./xx.yml...

func ParseSchema

func ParseSchema(schema string) (s *Schema, err error)

ParseSchema

Directories

Path Synopsis
example
internal

Jump to

Keyboard shortcuts

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