yaml

package
v0.0.0-...-5915c45 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package yaml for config provider

depend on github.com/beego/goyaml2

go install github.com/beego/goyaml2

Usage:

import(
 _ "github.com/flycash/beego-config/config/yaml"
   "github.com/flycash/beego-config/config"
)

cnf, err := config.NewConfig("yaml", "config.yaml")

More docs http://beego.me/docs/module/config.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadYmlReader

func ReadYmlReader(path string) (cnf map[string]interface{}, err error)

ReadYmlReader Read yaml file to map. if json like, use json package, unless goyaml2 package.

Types

type Config

type Config struct{}

Config is a yaml config parser and implements Config interface.

func (*Config) Parse

func (yaml *Config) Parse(filename string) (y config.Configer, err error)

Parse returns a ConfigContainer with parsed yaml config map.

func (*Config) ParseData

func (yaml *Config) ParseData(data []byte) (config.Configer, error)

ParseData parse yaml data

type ConfigContainer

type ConfigContainer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConfigContainer is a config which represents the yaml configuration.

func (*ConfigContainer) Bool

func (c *ConfigContainer) Bool(ctx context.Context, key string) (bool, error)

Bool returns the boolean value for a given key.

func (*ConfigContainer) DIY

func (c *ConfigContainer) DIY(ctx context.Context, key string) (v interface{}, err error)

DIY returns the raw value by a given key.

func (*ConfigContainer) DefaultBool

func (c *ConfigContainer) DefaultBool(ctx context.Context, key string, defaultVal bool) bool

DefaultBool return the bool value if has no error otherwise return the defaultVal

func (*ConfigContainer) DefaultFloat

func (c *ConfigContainer) DefaultFloat(ctx context.Context, key string, defaultVal float64) float64

DefaultFloat returns the float64 value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultInt

func (c *ConfigContainer) DefaultInt(ctx context.Context, key string, defaultVal int) int

DefaultInt returns the integer value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultInt64

func (c *ConfigContainer) DefaultInt64(ctx context.Context, key string, defaultVal int64) int64

DefaultInt64 returns the int64 value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultString

func (c *ConfigContainer) DefaultString(ctx context.Context, key string, defaultVal string) string

DefaultString returns the string value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultStrings

func (c *ConfigContainer) DefaultStrings(ctx context.Context, key string, defaultVal []string) []string

DefaultStrings returns the []string value for a given key. if err != nil return defaultVal

func (*ConfigContainer) Float

func (c *ConfigContainer) Float(ctx context.Context, key string) (float64, error)

Float returns the float value for a given key.

func (*ConfigContainer) GetSection

func (c *ConfigContainer) GetSection(ctx context.Context, section string) (map[string]string, error)

GetSection returns map for the given section

func (*ConfigContainer) Int

func (c *ConfigContainer) Int(ctx context.Context, key string) (int, error)

Int returns the integer value for a given key.

func (*ConfigContainer) Int64

func (c *ConfigContainer) Int64(ctx context.Context, key string) (int64, error)

Int64 returns the int64 value for a given key.

func (*ConfigContainer) OnChange

func (c *ConfigContainer) OnChange(ctx context.Context, key string, fn func(value string))

func (*ConfigContainer) SaveConfigFile

func (c *ConfigContainer) SaveConfigFile(ctx context.Context, filename string) (err error)

SaveConfigFile save the config into file

func (*ConfigContainer) Set

func (c *ConfigContainer) Set(ctx context.Context, key, val string) error

Set writes a new value for key.

func (*ConfigContainer) String

func (c *ConfigContainer) String(ctx context.Context, key string) (string, error)

String returns the string value for a given key.

func (*ConfigContainer) Strings

func (c *ConfigContainer) Strings(ctx context.Context, key string) ([]string, error)

Strings returns the []string value for a given key.

func (*ConfigContainer) Sub

func (*ConfigContainer) Unmarshaler

func (c *ConfigContainer) Unmarshaler(ctx context.Context, prefix string, obj interface{}, opt ...config.DecodeOption) error

Unmarshaler is similar to Sub

Jump to

Keyboard shortcuts

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