Consul K/V Store Implementation For Go
Enables Consul to be used as a configuration source in go applications
Dynamic Configuration with Consul's Key/Value Store Feature
Installation
go get -u github.com/gizemcifguvercin/consul-go
Create Your Own Config
Match with the data model on Consul config json
Example:
package main
type ApplicationConfig struct {
Salary string `json:"Salary"`
Title string `json:"Title"`
}
func NewApplicationConfig() ApplicationConfig {
return ApplicationConfig{}
}
Usage
package main
import (
Consul "github.com/gizemcifguvercin/consul-go"
"github.com/jasonlvhit/gocron"
)
func main() {
consulConfig := Consul.NewConsulConfig(5, "http://localhost:8500", "go", "")
consulWatcher := Consul.NewConsulWatcher(&consulConfig)
appConfig := NewApplicationConfig()
go func() {
gocron.Every(uint64(consulConfig.Interval)).Seconds().Do(consulWatcher.Watch, &appConfig)
<-gocron.Start()
}()
}
You can set some of Consul Config props with this order below;
Interval int
BaseUrl string
Prefix string
ACL string
This project is still developing. Feel free to give feedback or send pull request