yaml_config

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: MIT Imports: 8 Imported by: 11

README

yaml_config usage

package test

import (
	"testing"
	"github.com/stretchr/testify/assert"
	"github.com/hrygo/yaml_config"
)

func TestConfig(t *testing.T) {
	// CreateYamlFactory 创建一个yaml配置文件工厂
	// relativePath 相对工作目录的配置文件存储目录
	// fileName 配置文件名称
	// project 使用此模块的工程的名称(用以处理单元测试的路径问题)
	yc := yaml_config.CreateYamlFactory("test", "config.yml", "yaml_config")
	yc.ConfigFileChangeListen()

	word := yc.GetString("hello")
	assert.True(t, word == "word")
	word = yc.GetString("hello")
	assert.True(t, word == "word")

	cc := yc.Clone("test")
	cc.ConfigFileChangeListen()
	
	f := cc.GetFloat64("foo")
	assert.True(t, 1.0 == f)
	f = cc.GetFloat64("foo")
	assert.True(t, 1.0 == f)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasePath

func BasePath(project string) string

func CreateContainer

func CreateContainer(prefix string) *containers

CreateContainer 创建一个容器工厂

Types

type YmlConfig

type YmlConfig interface {
	ConfigFileChangeListen()
	Clone(fileName string) YmlConfig
	Get(keyName string) interface{}
	GetString(keyName string) string
	GetBool(keyName string) bool
	GetInt(keyName string) int
	GetInt32(keyName string) int32
	GetInt64(keyName string) int64
	GetFloat64(keyName string) float64
	GetDuration(keyName string) time.Duration
	GetStringSlice(keyName string) []string
	Viper() *viper.Viper
	BasePath() string
}

func CreateYamlFactory

func CreateYamlFactory(relativePath string, fileName string, project string) YmlConfig

CreateYamlFactory 创建一个yaml配置文件工厂 relativePath 相对工作目录的配置文件存储目录 fileName 配置文件名称 project 使用此模块的工程的名称(用以处理单元测试的路径问题)

Jump to

Keyboard shortcuts

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