mirror of
https://github.com/stashapp/stash-box.git
synced 2026-02-05 15:55:21 -06:00
* Schema/api changes for edit * Add StrSliceCompare * Edit Tag mutation * Tag edit creation * ApplyEdit for tags * Add migration * Edit comments * Add edits to tag resolver * QueryEdit filters * Add frontend tag editing support * Upgrade apollo-client to version 3 * Upgrade react-router to 5.2.0 * Upgrade react-hook-form and yup * Update various libraries * Search fixes * Show tag description and aliases * Update libraries * Move scene_tags in tag migrations * Add edits menu item and tweak graphql schema * Show merge edits for tags that have been merged Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
34 lines
971 B
Go
34 lines
971 B
Go
package utils
|
|
|
|
import "strings"
|
|
|
|
// FindField traverses a json map, searching for the field matching the
|
|
// qualified field string provided.
|
|
//
|
|
// For example: a qualifiedField of "foo" returns value of the "foo" key in the
|
|
// provided map. A qualifiedField of "foo.bar" will find the "foo" value, and
|
|
// if it is a map[string]interface{}, will return the "bar" value of that map.
|
|
// Returns the value and true if the value was found. Returns nil and false if
|
|
// the value was not found, or if one of the intermediate values was not a
|
|
// map[string]interface{}
|
|
func FindField(m map[string]interface{}, qualifiedField string) (interface{}, bool) {
|
|
const delimiter = "."
|
|
fields := strings.Split(qualifiedField, delimiter)
|
|
|
|
var current interface{}
|
|
current = m
|
|
for _, field := range fields {
|
|
asMap, ok := current.(map[string]interface{})
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
|
|
current, ok = asMap[field]
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
}
|
|
|
|
return current, true
|
|
}
|