Categorygithub.com/ah-its-andy/goconf
modulepackage
1.0.1
Repository: https://github.com/ah-its-andy/goconf.git
Documentation: pkg.go.dev

# README

goconf

Configuration providers for go inspired by .net core configuration libs.

Supportives:

  • Memory source
  • Environment variables
  • JSON file
  • YAML file
  • INI file

Features:

  • Get value by full path with key delimiter (e.g. application.bind_addr.port)
  • Cast value to specialized type with TypeConversionFunc
  • Bind configuration section to struct

Usage

  • package: github.com/ah-its-andy/goconf
// initialize on application startup
goconf.Init(func(b goconf.Builder) {
	b.AddSource(physicalfile.Yaml(/*yaml file path, absolute or relative  both supported*/)))
     .AddSource(physicalfile.Json(/*json file path, absolute or relative  both supported*/))
     .AddSource(goconf.EnvironmentVariable(/*prefix for filter environment variables*/))
     .AddSource(goconf.Memory(/*config map*/))
})

// use it anywhere
bindAddr, ok := goconf.GetString("application.bind_addr.addr") //Get string value

bindAddrWithDefault := goconf.GetStringOrDefault("application.bind_addr.addr", "default value") //returns default value when key is not found

castValue, ok := goconf.Cast("application.bind_addr.port", goconf.IntConversion) //cast value to int

castValueWithDefault := goconf.CastOrDefault("application.bind_addr.port", 0 /*default value*/, goconf.IntConversion) //cast value to int, returns default value when key is not found

section:= gocinf.GetSection("application") //get section

var application fakeStruct.Application
err := section.Bind(&application) //bind section to struct

Refer

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
Combine paths to one path with KeyDelimiter.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Get parent path.
No description provided by the author
Get last path segment.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author