mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Identify task (#1839)
* Add identify task * Change type naming * Debounce folder select text input * Add generic slice comparison function
This commit is contained in:
30
pkg/utils/reflect.go
Normal file
30
pkg/utils/reflect.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import "reflect"
|
||||
|
||||
// NotNilFields returns the matching tag values of fields from an object that are not nil.
|
||||
// Panics if the provided object is not a struct.
|
||||
func NotNilFields(subject interface{}, tag string) []string {
|
||||
value := reflect.ValueOf(subject)
|
||||
structType := value.Type()
|
||||
|
||||
if structType.Kind() != reflect.Struct {
|
||||
panic("subject must be struct")
|
||||
}
|
||||
|
||||
var ret []string
|
||||
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
field := value.Field(i)
|
||||
|
||||
kind := field.Type().Kind()
|
||||
if (kind == reflect.Ptr || kind == reflect.Slice) && !field.IsNil() {
|
||||
tagValue := structType.Field(i).Tag.Get(tag)
|
||||
if tagValue != "" {
|
||||
ret = append(ret, tagValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
Reference in New Issue
Block a user