Categorygithub.com/rakunlabs/chu
modulepackage
0.1.2
Repository: https://github.com/rakunlabs/chu.git
Documentation: pkg.go.dev

# README

chu

Configuration library to load from multiple sources.

go get github.com/rakunlabs/chu

Usage

Define a struct to hold the configuration.

type Config struct {
    Name string `cfg:"name"`
    Age  int    `cfg:"age"`
}

And load the configuration.

cfg := Config{}

if err := chu.Load(ctx, "test", &cfg); err != nil {
    return fmt.Errorf("failed to load config: %w", err)
}

The configuration will be loaded from the following sources in order:
- Default
- File
- Environment

Loaders

Check example folder to see how to use loaders with different kind of configuration.

Default

Default loader is used to set default values from tag default.

type Config struct {
    Name string `cfg:"name" default:"John"`
    Age  int    `cfg:"age"  default:"30"`
}

Default supports numbers, string, bool, time.Duration and pointer of that types.

File

File loader is used to load configuration from file.

First checking CONFIG_PATH env value and try current location to find in order of .toml, .yaml, .yml, .json extension with using given name.

Environment

Environment loader is used to load configuration from environment variables.

env or cfg tag can usable for environment loader.

export NAME=John
export AGE=30
type Config struct {
    Name string `cfg:"name"`
    Age  int    `cfg:"age"`
}

# Packages

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

# Functions

Load loads the configuration from loaders.
WithHook adds hooks for conversion.
WithHookSet sets the hooks for conversion.
WithLoaders sets the loaders to use when loading the configuration.
WithLogger sets the logger for logging.
WithTag sets the tag for the configuration.
WithWeaklyDashUnderscore sets the weakly dash underscore option.
WithWeaklyIgnoreSeperator sets the weakly ignore separator option.

# Variables

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

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author