mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-26 08:29:41 -05:00
+11



![coderabbitai[bot]](/avatar/4a08c485fbe908b864e4cf902fddaff20a4dd8a58faf8f65f051648bd2ef3153?size=40)




45a14bf2f2
Signed-off-by: MichaIng <micha@dietpi.com> Co-authored-by: Kevin B. <kurami32_kbm@proton.me> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Mattijs Bliek <mattijs@mattijsbliek.com> Co-authored-by: GammelSami <39372285+GammelSami@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: yzxcj797 <54314860+yzxcj797@users.noreply.github.com> Co-authored-by: yzxcj797 <yzxcj797@users.noreply.github.com> Co-authored-by: DireMunchkin <dire.munchkin@proton.me> Co-authored-by: Chris <39135018+Chri6s@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Aditya Raj Singh <github@adityaraj.com> Co-authored-by: tbsagdic <86909795+tbsagdic@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Ethan Lee Qi Yang <pluscompanyhqDEPT@gmail.com> Co-authored-by: Aditya Raj Singh <aditya@bncw.in> Co-authored-by: MichaIng <micha@dietpi.com> Co-authored-by: FandacqkaCorp <david@davidyloreto.com> Co-authored-by: FandacqkaCorp <275647464+FandacqkaCorp@users.noreply.github.com> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: connorjfarrell <connorjfarrell@users.noreply.github.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package settings
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
)
|
|
|
|
// ShareDefaultsValueAtPath returns the value at a dot-path on ShareDefaults.
|
|
// Unlike JSON marshaling, zero-valued fields (e.g. allowModify=false) are included.
|
|
func ShareDefaultsValueAtPath(d ShareDefaults, path string) (interface{}, bool) {
|
|
return valueAtStructJSONPath(reflect.ValueOf(d), path)
|
|
}
|
|
|
|
func valueAtStructJSONPath(v reflect.Value, path string) (interface{}, bool) {
|
|
parts := strings.Split(path, ".")
|
|
for i, part := range parts {
|
|
if v.Kind() == reflect.Pointer {
|
|
if v.IsNil() {
|
|
return nil, false
|
|
}
|
|
v = v.Elem()
|
|
}
|
|
if v.Kind() != reflect.Struct {
|
|
return nil, false
|
|
}
|
|
field, ok := structFieldByJSONTag(v, part)
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
v = field
|
|
if i == len(parts)-1 {
|
|
return v.Interface(), true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func structFieldByJSONTag(v reflect.Value, name string) (reflect.Value, bool) {
|
|
t := v.Type()
|
|
for i := 0; i < t.NumField(); i++ {
|
|
field := t.Field(i)
|
|
if !field.IsExported() {
|
|
continue
|
|
}
|
|
jsonTag := field.Tag.Get("json")
|
|
tagName := strings.Split(jsonTag, ",")[0]
|
|
if tagName == "" || tagName == "-" {
|
|
tagName = strings.ToLower(field.Name[:1]) + field.Name[1:]
|
|
}
|
|
if tagName != name {
|
|
continue
|
|
}
|
|
return v.Field(i), true
|
|
}
|
|
return reflect.Value{}, false
|
|
}
|