vhelp

package module
v0.0.0-...-2d29d61 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 6 Imported by: 1

README

Vhelp

Viper Config Helper, boot strapping of viper config and handles boiler plate

Features

  • Auto loads config in user home, current directory and /etc
  • If configured, binds a watcher to handle config changes
  • Auto calculates the binary name for the config dir ie if the binary is "example" it will look in:
    • /etc/example
    • $HOME/.example

Example usage

package main

import(
	"github.com/rob121/vhelp"
	"log"
	"github.com/fsnotify/fsnotify"
)

func main(){


  vhelp.OnChange(func(e fsnotify.Event) {
	  log.Println("Config file changed:", e.Name)
  })
  
  //loads config.json
  vhelp.Load("config")
  //fetchs config instance which is a *viper.Viper
  conf,err := vhelp.Get("config")

  if(err!=nil){

  	log.Println(err)
  }

	log.Println(conf.ConfigFileUsed())

	log.Println(conf)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPath

func AddPath(pth string)

func Get

func Get(name string) (*viper.Viper, error)

func Load

func Load(file string)

func OnChange

func OnChange(fn func(e fsnotify.Event))

func ResetPath

func ResetPath()

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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