configures

package module
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 27

README

Configures

Configures for Golang

Features

  • Open
  • Multi environment support。
  • Json
  • Yaml

Install

go get github.com/aacfactory/configures

Usage

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

store := configures.NewFileStore(path, "app", '.')

retriever, retrieverErr := configures.NewRetriever(configures.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

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

func NewYamlConfig

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

type Raw json.RawMessage

func (Raw) As

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

func (Raw) MarshalJSON

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

func (*Raw) UnmarshalJSON

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