feat(功能增强): 支持分区到结构体

This commit is contained in:
2026-08-19 12:28:42 +08:00
parent 96e3375441
commit ee27859f7e
+16
View File
@@ -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
}