Improved reflection in editform
This commit is contained in:
@ -1,24 +0,0 @@
|
||||
package utils
|
||||
|
||||
import "github.com/OneOfOne/xxhash"
|
||||
|
||||
// HashString returns a hash of the string.
|
||||
func HashString(item string) uint64 {
|
||||
h := xxhash.NewS64(0)
|
||||
h.Write([]byte(item))
|
||||
return h.Sum64()
|
||||
}
|
||||
|
||||
// HashStringsNoOrder returns a hash of the string slice contents, ignoring order.
|
||||
func HashStringsNoOrder(items []string) uint64 {
|
||||
sum := uint64(0)
|
||||
|
||||
for _, item := range items {
|
||||
h := xxhash.NewS64(0)
|
||||
h.Write([]byte(item))
|
||||
numHash := h.Sum64()
|
||||
sum += numHash
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
14
utils/HashStringsNoOrder.go
Normal file
14
utils/HashStringsNoOrder.go
Normal file
@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import "github.com/akyoto/hash"
|
||||
|
||||
// HashStringsNoOrder returns a hash of the string slice contents, ignoring order.
|
||||
func HashStringsNoOrder(items []string) uint64 {
|
||||
sum := uint64(0)
|
||||
|
||||
for _, item := range items {
|
||||
sum += hash.String(item)
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
@ -106,7 +106,20 @@ func RenderField(b *strings.Builder, v *reflect.Value, field reflect.StructField
|
||||
|
||||
// Embedded fields
|
||||
if field.Anonymous {
|
||||
RenderObject(b, fieldValue.Interface(), idPrefix)
|
||||
// If it's exported, render it normally.
|
||||
if field.PkgPath == "" {
|
||||
RenderObject(b, fieldValue.Interface(), idPrefix)
|
||||
}
|
||||
|
||||
// If it's an unexported struct, we try to access the field names
|
||||
// given to us from the anonymous struct on the actual object.
|
||||
if field.Type.Kind() == reflect.Struct {
|
||||
for i := 0; i < field.Type.NumField(); i++ {
|
||||
f := field.Type.Field(i)
|
||||
RenderField(b, v, f, idPrefix)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user