config

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 5 Imported by: 0

README

Test Status

Configurator Library for GO

This library allow you to load configurations from flags, env, json, yaml and much more through custom interface implementation.

import (
  ...

	"github.com/OpenRunic/config"
	"github.com/OpenRunic/config/options"
	"github.com/OpenRunic/config/env"
	"github.com/OpenRunic/config/json"
)

type ServerConfig struct {
  Host string
  Port int
}

var sc ServerConfig
_, err := config.Parse(
  options.New(),
  &sc,
  config.Register(json.New()),
  config.Register(env.New()),
  config.Add("host", "localhost", "Server hostname"),
  config.Add("port", 3000, "Server port"),
)

if err != nil {
  log.Fatal(err)
}

println("Server Host: ", sc.Host)
println("Server Port: ", sc.Port)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Options *options.Options
	Values  map[string]any
	// contains filtered or unexported fields
}

Configuration management struct

func New

func New(opts *options.Options, cbs ...WithConfigCallback) (*Config, error)

Create new instance of configurations with support for setup callbacks

func Parse added in v0.1.0

func Parse(opts *options.Options, data any, cbs ...WithConfigCallback) (*Config, error)

Create instance and parse configs

func (*Config) Add

func (c *Config) Add(field *reader.Field)

Add new field for config read

func (*Config) AddReader

func (c *Config) AddReader(r reader.Reader)

Add new configuration reader instance

func (*Config) Parse

func (c *Config) Parse(data any) error

Parse the configurations based of registered fields

type WithConfigCallback

type WithConfigCallback func(*Config) error

Callback type for configuration setup

func Add

func Add[T any](name string, value T, usage string) WithConfigCallback

Callback shortcut to register new field

func Register

func Register(r reader.Reader) WithConfigCallback

Callback to register new reader instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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