SpringProperties

package module
v0.0.0-...-2dd9ec7 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

spring-properties

「仅发布」属性值加载器

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindStruct

func BindStruct(p Properties, v reflect.Value, opt BindOption) error

BindStruct 对结构体进行属性值绑定

func BindStructField

func BindStructField(p Properties, v reflect.Value, str string, opt BindOption) error

BindStructField 对结构体的字段进行属性绑定

func BindValue

func BindValue(p Properties, v reflect.Value, key string, def interface{}, opt BindOption) error

BindValue 对任意 value 进行属性绑定

func New

func New() *defaultProperties

New defaultProperties 的构造函数

func Priority

func Priority(curr Properties, next Properties) *priorityProperties

Priority priorityProperties 的构造函数

func ResolveProperty

func ResolveProperty(p Properties, _ string, value interface{}) (interface{}, error)

ResolveProperty 解析属性值,查看其是否具有引用关系

func ToInt8SliceE

func ToInt8SliceE(i interface{}) ([]int8, error)

ToInt8SliceE casts an interface to a []int8 type.

func ToInt16SliceE

func ToInt16SliceE(i interface{}) ([]int16, error)

ToInt16SliceE casts an interface to a []int16 type.

func ToInt32SliceE

func ToInt32SliceE(i interface{}) ([]int32, error)

ToInt32SliceE casts an interface to a []int32 type.

func ToInt64SliceE

func ToInt64SliceE(i interface{}) ([]int64, error)

ToInt64SliceE casts an interface to a []int64 type.

func ToIntSliceE

func ToIntSliceE(i interface{}) ([]int, error)

ToIntSliceE casts an interface to a []int type.

func ToUint8SliceE

func ToUint8SliceE(i interface{}) ([]uint8, error)

ToUint8SliceE casts an interface to a []uint8 type.

func ToUint16SliceE

func ToUint16SliceE(i interface{}) ([]uint16, error)

ToUint16SliceE casts an interface to a []uint16 type.

func ToUint32SliceE

func ToUint32SliceE(i interface{}) ([]uint32, error)

ToUint32SliceE casts an interface to a []uint32 type.

func ToUint64SliceE

func ToUint64SliceE(i interface{}) ([]uint64, error)

ToUint64SliceE casts an interface to a []uint64 type.

func ToUintSliceE

func ToUintSliceE(i interface{}) ([]uint, error)

ToUintSliceE casts an interface to a []uint type.

Types

type BindOption

type BindOption struct {
	PrefixName string // 属性名前缀
	FullName   string // 完整属性名
	FieldName  string // 结构体字段的名称
}

BindOption 属性值绑定可选项

type Converter

type Converter interface{}

Converter 类型转换器,函数原型 func(string)(type,error)

type Properties

type Properties interface {

	// Load 加载属性配置,支持 properties、yaml 和 toml 三种文件格式。
	Load(filename string) error

	// Read 读取属性配置,支持 properties、yaml 和 toml 三种文件格式。
	Read(reader io.Reader, configType string) error

	// Convert 添加类型转换器
	Convert(fn Converter) error

	// Converters 返回类型转换器集合
	Converters() map[reflect.Type]Converter

	// Has 查询属性值是否存在,属性名称统一转成小写。
	Has(key string) bool

	// Bind 根据类型获取属性值,属性名称统一转成小写。
	Bind(key string, i interface{}) error

	// Get 返回属性值,不能存在返回 nil,属性名称统一转成小写。
	Get(key string) interface{}

	// GetFirst 返回 keys 中第一个存在的属性值,属性名称统一转成小写。
	GetFirst(keys ...string) interface{}

	// GetDefault 返回属性值,如果没有找到则使用指定的默认值,属性名称统一转成小写。
	GetDefault(key string, def interface{}) interface{}

	// Set 设置属性值,属性名称统一转成小写。
	Set(key string, value interface{})

	// Keys 返回所有键,属性名称统一转成小写。
	Keys() []string

	// Range 遍历所有的属性值,属性名称统一转成小写。
	Range(fn func(string, interface{}))

	// Fill 填充所有的属性值,属性名称统一转成小写。
	Fill(properties map[string]interface{})

	// Prefix 返回指定前缀的属性值集合,属性名称统一转成小写。
	Prefix(key string) map[string]interface{}

	// Group 返回指定前缀的属性值集合并进行分组,属性名称统一转成小写。
	Group(key string) map[string]map[string]interface{}
}

Properties 定义属性值接口

Jump to

Keyboard shortcuts

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