hot

package
v0.0.0-...-ac4703f Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueNotExist      = errors.New("hot: value not exist")
	ErrValueTypeAssertion = errors.New("hot: value type assertion no match")
)

ErrValueNotExist .

Functions

func Close

func Close()

Close closes file watcher

func Decode

func Decode(dst interface{}) error

Decode decodes file

func Init

func Init() (err error)

Init init config client

func Watch

func Watch(key string, dst interface{}) error

Watch watches a new toml config in a seperate goroutine

Types

type Event

type Event struct {
	Type  EventType
	Key   string
	Value *Value
}

Event is watch event

type EventFunc

type EventFunc func(v *Value) error

EventFunc .

type EventType

type EventType int

EventType is event type alias int

const (
	// EventAdd is file add event
	EventAdd EventType = iota
	// EventUpdate is file upfate event
	EventUpdate
	// EventRemove is file remove event
	EventRemove
)

type File

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

File has all values and a watcher

var (
	DefaultClient *File
)

DefaultClient .

func NewFile

func NewFile(base string) (f *File, err error)

NewFile .

func (*File) Close

func (f *File) Close() error

Close closes watcher

func (*File) Done

func (f *File) Done()

Done .

func (*File) Event

func (f *File) Event() <-chan Event

Event returns an event from f.ec

func (*File) Exists

func (f *File) Exists(key string) bool

Exists .

func (*File) Get

func (f *File) Get(key string) *Value

Get return value of file key.

func (*File) GetAll

func (f *File) GetAll() map[string]*Value

GetAll returns all values of files under base.

func (*File) Keys

func (f *File) Keys() []string

Keys returns all keys

func (*File) Watch

func (f *File) Watch(key string, cb EventFunc) error

Watch watches a config file and execute the callback function

type Value

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

Value is config value: json, toml, yaml, ini or plain text. Param blob keeps the origin form ([]byte) of value

func NewValue

func NewValue(val interface{}, blob []byte) *Value

NewValue new a value.

func (*Value) Blob

func (v *Value) Blob() ([]byte, error)

Blob returns the blob value

func (*Value) Bool

func (v *Value) Bool() (bool, error)

Bool returns bool value

func (*Value) Duration

func (v *Value) Duration() (time.Duration, error)

Duration returns a duration string

func (*Value) Float32

func (v *Value) Float32() (float32, error)

Float32 returns float32 value

func (*Value) Float64

func (v *Value) Float64() (float64, error)

Float64 returns float64 value

func (*Value) Int

func (v *Value) Int() (int, error)

Int returns int value

func (*Value) Int32

func (v *Value) Int32() (int32, error)

Int32 returns int32 value

func (*Value) Int64

func (v *Value) Int64() (int64, error)

Int64 return int64 value

func (*Value) String

func (v *Value) String() (string, error)

String returns string value

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(dst interface{}) error

UnmarshalJSON unmarshals JSON to struct

func (*Value) UnmarshalTOML

func (v *Value) UnmarshalTOML(dst interface{}) error

UnmarshalTOML unmarshals TOML to struct

func (*Value) UnmarshalYAML

func (v *Value) UnmarshalYAML(dst interface{}) error

UnmarshalYAML unmarshals JSON to struct

Jump to

Keyboard shortcuts

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