MCPcopy Index your code
hub / github.com/elastic/go-ucfg

github.com/elastic/go-ucfg @v0.9.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.9.1 ↗ · + Follow
736 symbols 2,544 edges 48 files 101 documented · 14% 3 cross-repo links updated 15d agov0.9.1 · 2026-03-05★ 858 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ci Go Report
Card codecov

ucfg - Universal Configuration

ucfg is a Golang library to handle hjson, json, and yaml configuration files in your Golang project. It was developed for the libbeat framework and used by all beats.

API Documentation

The full API Documentation can be found here.

Examples

A few examples on how ucfg can be used. All examples below assume, that the following packages are imported:

import (
    "github.com/elastic/go-ucfg"
    "github.com/elastic/go-ucfg/yaml"
)

Dot notations

ufcg allows you to load yaml configuration files using dots instead of indentation. For example instead of having:

config:
  user: name

with ucfg you can write:

config.user: name

This makes configurations easier and simpler.

To load such a config file in Golang, use the following command:

config, err := yaml.NewConfigWithFile(path, ucfg.PathSep("."))

Validation and Defaults

ucfg allows to automatically validate fields and set defaults for fields in case they are not defined.

// Defines struct to read config from
type ExampleConfig struct {
    Counter  int    `config:"counter" validate:"min=0, max=9"`
}

// Defines default config option
var (
    defaultConfig = ExampleConfig{
            Counter: 4,
    }
)

func main() {
    appConfig := defaultConfig // copy default config so it's not overwritten
    config, err := yaml.NewConfigWithFile(path, ucfg.PathSep("."))
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    err = config.Unpack(&appConfig)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

The above uses Counter as the config variable. ucfg assures that the value is between 0 and 9 and will return an error if this is not the case. In addition, if the value is not set, it will default to 4.

Requirements

ucfg has the following requirements:

  • Golang 1.10+

Extension points exported contracts — how you extend this code

Unpacker (Interface)
Unpacker type used by Unpack to allow types to implement custom configuration unpacking. [9 implementers]
unpack.go
Validator (Interface)
Validator interface provides additional validation support to Unpack. The Validate method will be executed for any type [4 …
validator.go
Initializer (Interface)
Initializer interface provides initialization of default values support to Unpack. The InitDefaults method will be execu [4 …
initializer.go
Error (Interface)
Error type returned by all public functions in go-ucfg. [1 implementers]
error.go
Option (FuncType)
Option type implementing additional options to be passed to go-ucfg library functions.
opts.go
FileLoader (FuncType)
FileLoader is used by NewFlagFiles to define customer file loading functions for different file extensions.
flag/file.go
BoolUnpacker (Interface)
BoolUnpacker interface specializes the Unpacker interface by casting values to bool when calling Unpack. [9 implementers]
unpack.go
ValidatorCallback (FuncType)
ValidatorCallback is the type of optional validator tags to be registered via RegisterValidator.
validator.go

Core symbols most depended-on inside this repo

Unpack
called by 76
unpack.go
PathSep
called by 70
opts.go
NewFrom
called by 67
ucfg.go
New
called by 47
ucfg.go
String
called by 43
path.go
Int
called by 35
getset.go
meta
called by 34
types.go
Len
called by 33
types.go

Shape

Function 318
Method 289
Struct 75
TypeAlias 35
Interface 16
FuncType 3

Languages

Go100%

Modules by API surface

types.go145 symbols
error.go46 symbols
reify_test.go45 symbols
variables.go37 symbols
opts.go31 symbols
validator_test.go27 symbols
ucfg.go27 symbols
path.go25 symbols
unpack_test.go24 symbols
initializer_test.go23 symbols
validator.go22 symbols
reify.go22 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add go-ucfg \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact