goconfig

package module
v0.0.0-...-d2ce694 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 6 Imported by: 0

README

GoConfig

This is an hierarchial config manager using redis. In case of website handling multiple country, we might need to maintain a config for payment username. But this key will vary for each country as shown below payment_username.sg = "hhhhh" payment_username.au = "yyyyy" all other countries will use: payment_username = "aaaaa"

In this case, if we feed in all these to our GoConfig payment_username = "aaaaa" payment_username.sg = "hhhhh" payment_username.au = "yyyyy"

and If we ask for payment_username.kr, it will return back "aaaaa" payment_username.sg, it will return back "hhhhh" accordingly.

Installation and Play

  • go get github.com/karuppaiah/goconfig
  • cd $GOPATH/src/github.com/karuppaiah/goconfig
  • install dep(https://github.com/golang/dep)
  • dep ensure
  • cd examples
  • go run main.go

Usage

    // Handle errors accordingly
	redisClient, err := config.DefaultRedis("", "", "", 0)
	if err != nil {
		log.Errorln(err)
	}
	goConfig := config.NewGoConfig(redisClient, ".")
	err = goConfig.Set("a.b.c", "a")
	if err != nil {
		log.Errorln(err)
	}
    val, err := goConfig.Get("a.b.c")
	if err != nil {
		log.Errorln(err)
	}

TODO :

  • Instead of storing just string values. See possibility to store any type of value.
  • Option to Load Data on startup and keep it in memory from DB
  • Docker image and publish in hub.docker.com
  • Write unit testing
  • Flutter/web assembly frontend to playaround (++)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRedis

func DefaultRedis(host string, password string, port string, dbNum int) (*redis.Client, error)

DefaultRedis allows us to create a redis client by passing respective params If you want to default to localhost, 6370 and db 0 with password "", leave all empty and pass dbNum as 0.

Types

type GoConfig

type GoConfig struct {
	RedisClient     *redis.Client
	ConfigList      *list.List
	DelimiterForKey string
}

GoConfig is the representation of the heirarchial storage and retreival system

func NewGoConfig

func NewGoConfig(redisClient *redis.Client, delimiterForKey string) *GoConfig

NewGoConfig return the singleton GoConfig

func (*GoConfig) Delete

func (g *GoConfig) Delete(key string) error

Delete will Delete the key in redis store

func (*GoConfig) Get

func (g *GoConfig) Get(keyStr string) (string, error)

Get will retrieve the value in the respective key. If key doesnt exist it will recursively check if parent has the value and return the value whoever has. Always child with value gets high preference in Get. Please note that key will be like a.b which says under a node, b will might or might not have value. Here separator in key is "." If b exists, then its value is returned, else if a exists , then its value is returned else error returned

func (*GoConfig) GetAll

func (g *GoConfig) GetAll(keyStr string) (map[string]string, error)

GetAll will get all list of key values as map[string]string

func (*GoConfig) Set

func (g *GoConfig) Set(key string, value string) error

Set will store the value in the respective key. If key doesnt exist it will store the key and put the value inside it Please note that key will be like a.b which says under a node, b will have value. Here separator in key is "."

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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