mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-06-24 09:41:00 +00:00
feat: support map and slice types in OBI attributes
Extends OBI header parsing to recognize and deserialize JSON-like arrays and objects. Introduces safe conversion utilities in `obiutils` to cast generic interface values into typed maps, and exposes them via new `BioSequence` methods. Header values are now marshaled, quote-normalized, and formatted for map and slice types.
This commit is contained in:
@@ -276,6 +276,44 @@ func InterfaceToStringMap(i interface{}) (val map[string]string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func InterfaceToMapOfIntSlice(i interface{}) (val map[string][]int, err error) {
|
||||
err = nil
|
||||
switch m := i.(type) {
|
||||
case map[string][]int:
|
||||
val = m
|
||||
case map[string]interface{}:
|
||||
val = make(map[string][]int, len(m))
|
||||
for k, v := range m {
|
||||
val[k], err = InterfaceToIntSlice(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
default:
|
||||
err = &NotAMapInt{"value attribute cannot be casted to a map[string][]int"}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func InterfaceToMapOfStringSlice(i interface{}) (val map[string][]string, err error) {
|
||||
err = nil
|
||||
switch m := i.(type) {
|
||||
case map[string][]string:
|
||||
val = m
|
||||
case map[string]interface{}:
|
||||
val = make(map[string][]string, len(m))
|
||||
for k, v := range m {
|
||||
val[k], err = InterfaceToStringSlice(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
default:
|
||||
err = &NotAMapInt{"value attribute cannot be casted to a map[string][]string"}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func InterfaceToStringSlice(i interface{}) (val []string, err error) {
|
||||
err = nil
|
||||
|
||||
|
||||
Reference in New Issue
Block a user