consul_go

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsulClient

type ConsulClient struct {
	APIClient    *api.Client
	QueryOptions *api.QueryOptions
	Config       *ConsulConfig
	OnLoad       bool
}

func NewConsulClient

func NewConsulClient() *ConsulClient

func (*ConsulClient) Read

func (c *ConsulClient) Read() (result string)

type ConsulConfig

type ConsulConfig struct {
	Interval int
	BaseUrl  string
	Prefix   string
	ACL      string
}

func NewConsulConfig

func NewConsulConfig(interval int, baseUrl string, prefix string, acl string) ConsulConfig

type ConsulWatcher

type ConsulWatcher struct {
	ConsulClient *ConsulClient
}

func NewConsulWatcher

func NewConsulWatcher(c *ConsulConfig) ConsulWatcher

func (*ConsulWatcher) Watch

func (w *ConsulWatcher) Watch(appConfig interface{})

Jump to

Keyboard shortcuts

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