package toml import ( "reflect" "strings" "dove/utils/errors" ) func Parse(target any) error { targetValue := reflect.ValueOf(target) if targetValue.Kind() != reflect.Pointer || targetValue.Elem().Kind() != reflect.Struct { return errors.Error(ParseTargetMustBeStructPtr) } ApplyDefaults(target) if loadedData == nil { return nil } sectionName := resolveSectionName(targetValue) sectionData, exists := loadedData[sectionName] if !exists { return nil } sectionBytes, marshalError := marshalSection(sectionData) if marshalError != nil { return errors.Error(ConfigSectionInvalid, sectionName) } return unmarshalContent(sectionBytes, target) } func resolveSectionName(targetValue reflect.Value) string { typeName := targetValue.Elem().Type().Name() return strings.ToLower(typeName) }