owl

package module
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 11 Imported by: 3

README

GoDoc license Test Coverage Status Go Report Card Release GitHub release (latest by date)

owl

Go yaml configuration lib,can get config value from yaml file or etcd cluster like viper lib.

Owl also support binary cli, help you store yaml file's content into etcd cluster.

1. Install as cli

# macos 
wget https://github.com/gsxhnd/owl/releases/latest/download/owl-darwin-amd64 -O owl
# linux x64
wget https://github.com/gsxhnd/owl/releases/latest/download/owl-linux-amd64 -O owl
# windows x64
wget https://github.com/gsxhnd/owl/releases/latest/download/owl-windows-amd64.exe -O owl.exe

chmod +x /usr/local/bin/owl

## show version
owl version

owl version:  1.5.1
owl commit:  6840df54b9a566acb78b36195fd9e826bb04d6cf
owl tree state:  clean
owl build date:  2020-12-29T15:49:14+0800
go version:  go1.15.6
go compiler:  gc
platform:  darwin/amd64
1.1 CLI Usage
NAME:
   owl - owl

USAGE:
   owl [global options] command [command options] [arguments...]

COMMANDS:
   get       get value by key
   get_keys  get keys by prefix
   put       read file then put value to etcd
   delete    delete value by key
   version   show version
   help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --endpoint value, -e value  (default: "http://127.0.0.1:2379")
   --help, -h                  show help (default: false)

2. Add as lib

go get -u github.com/gsxhnd/owl
Putting Values into owl
Reading Config Files

Owl requires minimal configuration so it knows where to look for config files. Owl just supports YAML file.

Examples:

owl.SetConfName("test.yaml")
owl.AddConfPath("./mock/")
err := owl.ReadConf()
if err != nil { // Handle errors reading the config file
	panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
Getting Values From

In owl, there are a few ways to get a value depending on the value’s type. The following functions and methods exist:

  • Get(key string) : interface{}
  • GetBool(key string) : bool
  • GetFloat64(key string) : float64
  • GetInt(key string) : int
  • GetIntSlice(key string) : []int
  • GetString(key string) : string
  • GetStringMap(key string) : map[string]interface{}
  • GetStringMapString(key string) : map[string]string
  • GetStringSlice(key string) : []string
  • GetAll() : map[string]interface{}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FileNotExistError = errors.New("file not exist")
	FileIsDirError    = errors.New("path is dir")
	FilenameError     = errors.New("filename is not set")
)

Functions

func AddConfPath

func AddConfPath(path string)

AddConfPath adds a path for owl to search for the config file in.

func DeleteRemote

func DeleteRemote(key string) error

DeleteRemote value from etcd.

func Get

func Get(key string) interface{}

Get returns the value associated with the key as interface.

func GetAll

func GetAll() map[string]interface{}

GetAll returns the all value as map.

func GetBool

func GetBool(key string) bool

GetBool returns the value associated with the key as bool.

func GetFloat64

func GetFloat64(key string) float64

GetFloat64 returns the value associated with the key as float64.

func GetInt

func GetInt(key string) int

GetInt returns the value associated with the key as int.

func GetInt64

func GetInt64(key string) int64

GetInt64 returns the value associated with the key as int64.

func GetIntSlice

func GetIntSlice(key string) []int

GetIntSlice returns the value associated with the key as int slice.

func GetRemote

func GetRemote(key string) (string, error)

GetRemote get config content from etcd by key

func GetRemoteKeys

func GetRemoteKeys(prefix string) ([]string, error)

GetRemoteKeys get keys from etcd by prefix

func GetString

func GetString(key string) string

GetString returns the value associated with the key as a string.

func GetStringMap

func GetStringMap(key string) map[string]interface{}

GetStringMap returns the value associated with the key as string map.

func GetStringMapString

func GetStringMapString(key string) map[string]string

func GetStringSlice

func GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as string slice.

func GetUint

func GetUint(key string) uint

GetUint returns the value associated with the key as uint.

func PutRemote

func PutRemote(key, value string) error

PutRemote value into etcd.

func ReadConf

func ReadConf() error

ReadConf will read a configuration file, setting existing keys to nil if the key does not exist in the file.

func ReadInConf

func ReadInConf(content []byte) error

ReadInConf will read a configuration file, setting existing keys to nil if the key does not exist in the file.

func SetConfName

func SetConfName(name string)

func SetRemoteAddr

func SetRemoteAddr(addr []string) error

SetRemoteAddr set url for the etcd.

func Watcher

func Watcher(key string, c chan string)

Watcher watch key's value in etcd

Types

type Owl

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

Owl is a lib for get configure value from etcd.

func New

func New() *Owl

New returns an initialized Owl instance.

func (*Owl) AddConfPath

func (o *Owl) AddConfPath(path string)

func (*Owl) DeleteRemote

func (o *Owl) DeleteRemote(key string) error

func (*Owl) Get

func (o *Owl) Get(key string) interface{}

func (*Owl) GetAll

func (o *Owl) GetAll() map[string]interface{}

func (*Owl) GetBool

func (o *Owl) GetBool(key string) bool

func (*Owl) GetFloat64

func (o *Owl) GetFloat64(key string) float64

func (*Owl) GetInt

func (o *Owl) GetInt(key string) int

func (*Owl) GetInt64

func (o *Owl) GetInt64(key string) int64

func (*Owl) GetIntSlice

func (o *Owl) GetIntSlice(key string) []int

func (*Owl) GetRemote

func (o *Owl) GetRemote(key string) (string, error)

func (*Owl) GetRemoteKeys

func (o *Owl) GetRemoteKeys(prefix string) ([]string, error)

func (*Owl) GetString

func (o *Owl) GetString(key string) string

func (*Owl) GetStringMap

func (o *Owl) GetStringMap(key string) map[string]interface{}

func (*Owl) GetStringMapString

func (o *Owl) GetStringMapString(key string) map[string]string

func (*Owl) GetStringSlice

func (o *Owl) GetStringSlice(key string) []string

func (*Owl) GetUint

func (o *Owl) GetUint(key string) uint

func (*Owl) PutRemote

func (o *Owl) PutRemote(key, value string) error

func (*Owl) ReadConf

func (o *Owl) ReadConf() error

func (*Owl) ReadInConf

func (o *Owl) ReadInConf(content []byte) error

func (*Owl) SetConfName

func (o *Owl) SetConfName(name string)

func (*Owl) SetRemoteAddr

func (o *Owl) SetRemoteAddr(addr []string) error

func (*Owl) Watcher

func (o *Owl) Watcher(key string, c chan string)

Directories

Path Synopsis
cli
cmd

Jump to

Keyboard shortcuts

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