Identify task (#1839)

* Add identify task
* Change type naming
* Debounce folder select text input
* Add generic slice comparison function
This commit is contained in:
WithoutPants
2021-10-28 14:25:17 +11:00
committed by GitHub
parent c93b5e12b7
commit 0f64954e5b
70 changed files with 5882 additions and 291 deletions

30
pkg/utils/reflect.go Normal file
View 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
}