config

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 4 Imported by: 0

README

config


一个简易的yaml文件读取及配置管理工具

主要功能


  • yaml文件读取
  • 支持自定义配置结构体,只需要实现IConfig接口
  • 支持多配置结构体按需注册
  • 支持yaml文件引用环境变量

Example


package main

import (
	"fmt"
	"github.com/caibo86/config"
	"os"
)

type Example struct {
	Level   int32  `yaml:"level"`
	Size    int32  `yaml:"size"`
	Async   bool   `yaml:"async"`
	LogFile string `yaml:"logFile"`
}

// GetType implements IConfig
func (e *Example) GetType() string {
	return "example"
}

func main() {
	_ = os.Setenv("SERVER_ID", "10001")
	config.Load("example.yaml", &Example{})
	example := config.Get("example").(*Example)
	fmt.Printf("%+v\n", *example)
}

Output:

{Level:1 Size:100 Async:true LogFile:example_10001.log}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(filename string, configs ...IConfig)

Load 加载全局配置

Types

type IConfig

type IConfig interface {
	GetType() string
}

IConfig 配置接口

func Get

func Get(t string) IConfig

Get 获取指定配置

type Manager

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

Manager 配置管理器

func (*Manager) String

func (m *Manager) String() string

String 实现fmt.Stringer接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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