mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
First version of obimatrix
Former-commit-id: 6e09eb0dd75bc688a6c83ef40dd88658fb1b296e
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package obiutils
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// InterfaceToString converts an interface value to a string.
|
||||
//
|
||||
@ -64,3 +68,25 @@ func InterfaceToBool(i interface{}) (val bool, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MapToMapInterface converts a map to a map of type map[string]interface{}.
|
||||
//
|
||||
// It takes an interface{} parameter `m` which represents the map to be converted.
|
||||
//
|
||||
// It returns a map[string]interface{} which is the converted map. If the input map is not of type map[string]interface{},
|
||||
// it panics and logs an error message.
|
||||
func MapToMapInterface(m interface{}) map[string]interface{} {
|
||||
if IsAMap(m) {
|
||||
reflectMap := reflect.ValueOf(m)
|
||||
keys := reflectMap.MapKeys()
|
||||
val := make(map[string]interface{}, len(keys))
|
||||
for k := range keys {
|
||||
val[keys[k].String()] = reflectMap.MapIndex(keys[k]).Interface()
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
log.Panic("Invalid map type")
|
||||
return make(map[string]interface{})
|
||||
}
|
||||
|
Reference in New Issue
Block a user