cfg

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: Apache-2.0 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 added in v0.2.0

func Get(key string) string

func New

func New(opts Opts) (cfg, error)

func Rebuild added in v0.2.0

func Rebuild()

func SetErrorf added in v0.2.0

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

func SetInfof added in v0.2.0

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

func SetWarnf added in v0.2.0

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