mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Removed unused code
This commit is contained in:
parent
c01ce35f04
commit
4e0a47d2a6
1 changed files with 0 additions and 112 deletions
112
utils/mapping.go
112
utils/mapping.go
|
@ -1,113 +1,9 @@
|
|||
// Adapted from https://github.com/nytlabs/gojsonexplode
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const delimiter = "."
|
||||
|
||||
func flattenList(l []interface{}, parent string, delimiter string) (map[string]interface{}, error) {
|
||||
var err error
|
||||
var key string
|
||||
j := make(map[string]interface{})
|
||||
for k, i := range l {
|
||||
if len(parent) > 0 {
|
||||
key = parent + delimiter + strconv.Itoa(k)
|
||||
} else {
|
||||
key = strconv.Itoa(k)
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case nil:
|
||||
j[key] = v
|
||||
case int:
|
||||
j[key] = v
|
||||
case float64:
|
||||
j[key] = v
|
||||
case string:
|
||||
j[key] = v
|
||||
case bool:
|
||||
j[key] = v
|
||||
case []interface{}:
|
||||
out := make(map[string]interface{})
|
||||
out, err = flattenList(v, key, delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for newkey, value := range out {
|
||||
j[newkey] = value
|
||||
}
|
||||
case map[string]interface{}:
|
||||
out := make(map[string]interface{})
|
||||
out, err = flattenMap(v, key, delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for newkey, value := range out {
|
||||
j[newkey] = value
|
||||
}
|
||||
default:
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
return j, nil
|
||||
}
|
||||
|
||||
func flattenMap(m map[string]interface{}, parent string, delimiter string) (map[string]interface{}, error) {
|
||||
var err error
|
||||
j := make(map[string]interface{})
|
||||
for k, i := range m {
|
||||
if len(parent) > 0 {
|
||||
k = parent + delimiter + k
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case nil:
|
||||
j[k] = v
|
||||
case int:
|
||||
j[k] = v
|
||||
case float64:
|
||||
j[k] = v
|
||||
case string:
|
||||
j[k] = v
|
||||
case bool:
|
||||
j[k] = v
|
||||
case []interface{}:
|
||||
out := make(map[string]interface{})
|
||||
out, err = flattenList(v, k, delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for key, value := range out {
|
||||
j[key] = value
|
||||
}
|
||||
case map[string]interface{}:
|
||||
out := make(map[string]interface{})
|
||||
out, err = flattenMap(v, k, delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for key, value := range out {
|
||||
j[key] = value
|
||||
}
|
||||
default:
|
||||
//nothing
|
||||
}
|
||||
}
|
||||
return j, nil
|
||||
}
|
||||
|
||||
func FlattenMap(input map[string]interface{}) (map[string]interface{}, error) {
|
||||
var flattened map[string]interface{}
|
||||
var err error
|
||||
flattened, err = flattenMap(input, "", delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return flattened, nil
|
||||
}
|
||||
|
||||
func ToMap(rec interface{}) (map[string]interface{}, error) {
|
||||
// Convert to JSON...
|
||||
b, err := json.Marshal(rec)
|
||||
|
@ -132,11 +28,3 @@ func ToStruct(m map[string]interface{}, rec interface{}) error {
|
|||
err = json.Unmarshal(b, &rec)
|
||||
return err
|
||||
}
|
||||
|
||||
func Flatten(input interface{}) (map[string]interface{}, error) {
|
||||
m, err := ToMap(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return FlattenMap(m)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue