yamlConfig

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Example
package main

import "fmt"

type MyConfigAddress struct {
	Host string `config:"host"`
	Port int    `config:"port"`
}

type MyConfig struct {
	Address MyConfigAddress `config:"address"`
	Name    string          `config:"name"`
}

func DefaultConfig() *MyConfig {
	return &MyConfig{
		Address: MyConfigAddress{
			Host: "unknown",
			Port: 80,
		},
		Name: "unknown",
	}
}

func main() {
	// This example demonstrates how to use YAML loader.
	//
	// First, create loader:
	loader, err := NewFileLoaderBuilder().
		WithFile("config.global.yaml", false).
		WithFile("config.local.yaml", false).
		Build()
	if err != nil {
		panic(err)
	}

	// Then load configuration:
	config := DefaultConfig()
	err = loader.Load(config)
	if err != nil {
		panic(err)
	}

	// Now you can use config.
	// For example, print it:
	fmt.Println(*config)

}
Output:

{{google.com 91} My App}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileLoaderBuilder

func NewFileLoaderBuilder() *configs.FileLoaderBuilder

Types

type Converter

type Converter struct {
}

func NewConverter

func NewConverter() *Converter

func (*Converter) Convert

func (that *Converter) Convert(dst interface{}, src map[string]interface{}) error

type Source

type Source struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳