mirror of
https://github.com/xiaoqidun/goini.git
synced 2026-08-23 06:14:41 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee27859f7e | ||
|
|
96e3375441 |
@@ -1,6 +1,6 @@
|
|||||||
# GoINI [](https://pkg.go.dev/github.com/xiaoqidun/goini)
|
# GoINI [](https://pkg.go.dev/github.com/xiaoqidun/goini)
|
||||||
|
|
||||||
零依赖、够简单的 Go 语言 INI 配置文件读写库
|
够简单、零依赖的 Go 语言 INI 配置文件读写库
|
||||||
|
|
||||||
# 安装方法
|
# 安装方法
|
||||||
|
|
||||||
|
|||||||
@@ -288,3 +288,19 @@ func (ini *GoINI) MapToStruct(ptr interface{}) error {
|
|||||||
ini.mapStruct(v)
|
ini.mapStruct(v)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MapSectionToStruct 将指定分区映射到一个结构体
|
||||||
|
// 入参: name 分区名称, ptr 结构体指针
|
||||||
|
// 返回: error 错误信息
|
||||||
|
func (ini *GoINI) MapSectionToStruct(name string, ptr interface{}) error {
|
||||||
|
v := reflect.ValueOf(ptr)
|
||||||
|
if !v.IsValid() || v.Kind() != reflect.Ptr || v.IsNil() {
|
||||||
|
return errStructPointerRequired
|
||||||
|
}
|
||||||
|
v = v.Elem()
|
||||||
|
if v.Kind() != reflect.Struct {
|
||||||
|
return errStructPointerRequired
|
||||||
|
}
|
||||||
|
ini.mapSection(v, ini.normalizeSection(name))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user