configuares

package module
v1.12.0 Latest Latest
Warning

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

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

README

概要

配置工具

特性

  • 开放:可根据实际情况进行额外扩展。
  • 多环境支持:指定激活的配置文件,并合并进根配置。
  • 多配置语言:当前支持 JSON 与 YAML 。

安装

go get github.com/aacfactory/configuares

使用

path, err := filepath.Abs("./_example/json")
if err != nil {
    // handle error
    return
}

// 构建配置存储器
store := configuares.NewFileStore(path, "app", '.')

// 构建配置读取器
retriever, retrieverErr := configuares.NewRetriever(configuares.RetrieverOption{
    Active: "dev",
    Format: "JSON",
    Store:  store,
})

if retrieverErr != nil {
    // handle error
    return
}

// 获取配置内容
config, configErr := retriever.Get()
if configErr != nil {
    // handle error
    return
}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config interface {
	Raw() []byte
	As(v interface{}) (err error)
	Get(path string, v interface{}) (has bool, err error)
	Node(path string) (v Config, has bool)
}

func NewJsonConfig added in v1.4.0

func NewJsonConfig(raw []byte) (v Config, err error)

func NewYamlConfig added in v1.4.0

func NewYamlConfig(raw []byte) (v Config, err error)

type FileStore

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

func (*FileStore) Read

func (store *FileStore) Read() (root []byte, subs map[string][]byte, err error)

type Raw added in v1.1.0

type Raw json.RawMessage

func (Raw) As added in v1.1.1

func (r Raw) As(v interface{}) (err error)

func (Raw) MarshalJSON added in v1.2.2

func (r Raw) MarshalJSON() ([]byte, error)

func (*Raw) UnmarshalJSON added in v1.2.2

func (r *Raw) UnmarshalJSON(data []byte) error

type Retriever

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

func NewRetriever

func NewRetriever(option RetrieverOption) (retriever *Retriever, err error)

func (*Retriever) Get

func (retriever *Retriever) Get() (v Config, err error)

type RetrieverOption

type RetrieverOption struct {
	Active string
	Format string
	Store  Store
}

type Store

type Store interface {
	Read() (root []byte, subs map[string][]byte, err error)
}

func NewFileStore

func NewFileStore(configPath string, prefix string, splitter byte) Store

Jump to

Keyboard shortcuts

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