cfg

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 7 Imported by: 0

README

cfg

Yet another config package

Features
  • Read from file
  • Read from environment variable
  • Hot reload of the file
Usage
package main

import (
	"context"
	"fmt"

	"github.com/infiniteloopcloud/cfg"
)

var config cfg.Config

func main() {
	var err error
	config, err = cfg.New(cfg.Opts{
		Path:      "./config.json",
		HotReload: true,
		Infof: func(ctx context.Context, format string, args ...interface{}) {
			fmt.Printf(format+"\n", args...)
		},
	})
	if err != nil {
		// TODO err
    }

	// First it reads from the ./config.json (it's a map[string]string under the hood)
	// After it reads with os.Getenv
	config.Get("something")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(key string) string

func New

func New(opts Opts) (cfg, error)

func Rebuild

func Rebuild()

func SetErrorf

func SetErrorf(fn func(ctx context.Context, err error, format string, args ...interface{}))

func SetInfof

func SetInfof(fn func(ctx context.Context, format string, args ...interface{}))

func SetWarnf

func SetWarnf(fn func(ctx context.Context, format string, args ...interface{}))

Types

type Config

type Config interface {
	Get(key string) string
}

type Opts

type Opts struct {
	Path      string
	HotReload bool
	Errorf    func(ctx context.Context, err error, format string, args ...interface{})
	Infof     func(ctx context.Context, format string, args ...interface{})
	Warnf     func(ctx context.Context, format string, args ...interface{})
}

Jump to

Keyboard shortcuts

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