Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 2.64 KB

README.md

File metadata and controls

58 lines (45 loc) · 2.64 KB

xybor founder Go Reference GitHub Repo stars GitHub top language GitHub go.mod Go version GitHub release (release name instead of tag name) Codacy Badge Codacy Badge Go Report

Introduction

Package xyconfig supports to thread-safe read, control, and monitor configuration files.

Get started

var config = xyconfig.GetConfig("app")

// Read config from a string with the priority is 10.
config.ReadBytes(xyconfig.JSON, 10, []byte(`{"general": {"timeout": 3.14}}`))

// Read from files.
config.Read("config/10-default.ini")
config.Read("config/20-override.yml")
config.Read("10-dev.env")

// Load global environment variables to config files.
config.Read("env")

// Read config from aws s3 bucket.
config.Read("s3://bucket/30-item.ini")

fmt.Println(config.MustGet("general.timeout").MustFloat())

config.AddHook("general.timeout", func (e xyconfig.Event) {
    var timeout, ok = e.New.AsFloat()
    if !ok {
        return
    }
    SetTimeoutToSomeThing(timeout)
})

config.AddHook("general", func (e Event) {
    var general = e.New.MustConfig()
    var timeout = general.MustGet("timeout").MustFloat()
    SetTimeoutToSomething(timeout)
})

Benchmark

Operation Time Objects Allocated
Get 70 ns/op 0 allocs/op
ChangeConfig 413763 ns/op 724 allocs/op
WriteFile 335892 ns/op 3 allocs/op