config

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

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 10 Imported by: 1

README

Config

Flex Config is a lightweight yet powerful configuration manager for Go projects. It takes advantage of Dot-env (.env) files and OS environment variables alongside config files (JSON, YAML) to meet all of your requirements.

Documentation

Required Go Version

It requires Go v1.16 or newer versions.

Installation

To install this package run the following command in the root of your project.

go get github.com/20326/flexbox/config
Quick Start

The following example demonstrates how to use a JSON configuration file.

// The configuration struct
type MyConfig struct {
    Addr       string
    Debug      bool
    Rand       float64
}

// Create an instance of the configuration struct
myConfig := MyConfig{}

// Create a Config instance and load it from a yaml file
errs := config.New("etc").LoadFile("app.yaml", &myConfig).End()

if len(errs) > 0 {
	log.Fatalf("errors: %v", errs)
}

// Use `myConfig`...
Types
  • Json: It loads using a JSON file.
  • Yaml: It feeds using a YAML file.
  • DotEnv: It feeds using a dot env (.env) file.

The .env file:

ENV=production
Load Priority

the priority of loading configuration data:

filename.${env}.ext (if exists) > filename.ext

PS: Env: default local

DotEnv

The DotEnv package to load .env files. The example below shows how to use the DotEnv feeder.

The .env file:

License

Flex Config is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cwd string
)
View Source
var (
	Version = "0.1.0"
)

Functions

func GetVersion

func GetVersion() string

func SelfDir

func SelfDir() string

Types

type SuperAgent

type SuperAgent struct {
	Debug  bool
	Env    string
	Path   string
	Errors []error
	// contains filtered or unexported fields
}

A SuperAgent is a object storing all request data for client.

func New

func New(dir string) *SuperAgent

func (*SuperAgent) End

func (s *SuperAgent) End() []error

func (*SuperAgent) LoadData

func (s *SuperAgent) LoadData(data []byte, ext string, object interface{}) *SuperAgent

func (*SuperAgent) LoadFile

func (s *SuperAgent) LoadFile(name string, object interface{}) *SuperAgent

func (*SuperAgent) SetLogger

func (s *SuperAgent) SetLogger(logger *log.Logger) *SuperAgent

func (*SuperAgent) SetPath

func (s *SuperAgent) SetPath(dir string) *SuperAgent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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