gookit/properties - GO 实现的 Java Properties 格式内容解析、编码和解码库
- 通用的 Java
properties格式内容解析器 - 支持像
json包一样的Marshal和Unmarshal -
支持以
!,#开头的行注释- 增强: 也额外支持
//,/* multi line comments */
- 增强: 也额外支持
-
支持多行字符串值,以
\\结尾进行换行- 增强: 也额外支持
'''multi line string'''',"""multi line string"""
- 增强: 也额外支持
- 支持值引用 var 解析。format:
${some.other.key} - 支持 ENV 变量解析。format:
${APP_ENV},${APP_ENV | default}
使用示例
解析并绑定到结构体
package main
import (
"fmt"
"github.com/gookit/properties"
)
func Example() {
text := `
# properties string
name = inhere
age = 200
`
p, err := properties.Parse(text)
if err != nil {
panic(err)
}
type MyConf struct {
Name string `properties:"name"`
Age int `properties:"age"`
}
cfg := &MyConf{}
err = p.MapStruct("", cfg)
if err != nil {
panic(err)
}
fmt.Println(*cfg)
// Output:
// {inhere 200}
}