Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DiffTagName = "json"
Functions ¶
func DiffFields ¶ added in v0.0.4
DiffFields returns different field names
Example ¶
type User struct { ID int `json:"id"` Name string `json:"name"` Age int `json:"age"` Gender null.String `json:"gender"` } a := &User{ID: 1, Name: "foo", Age: 1, Gender: null.StringFrom("Male")} b := &User{ID: 2, Name: "bar", Age: 1} got, _ := structs.DiffFields( a, b, ) fmt.Printf("%+v", got)
Output: [id name gender]
func PropagateValues ¶
PropagateValues copy from `src` field values to `dst`.
Example ¶
package main import ( "fmt" "github.com/takashabe/structs" ) func main() { type User struct { ID int Name string Age int } a := &User{ID: 1, Name: "foo", Age: 1} b := &User{ID: 2, Name: "bar", Age: 2} got, _ := structs.PropagateValues( a, b, structs.WithIgnoreFields("ID", "Name"), structs.WithValue(1), ) fmt.Printf("%+v", got) }
Output: &{ID:2 Name:bar Age:1}
Types ¶
type Option ¶ added in v0.0.4
type Option func(srcValue, dstValue reflect.Value, srcField reflect.StructField) bool
Option represents whether to target field.
func WithDefaultValue ¶ added in v0.0.4
func WithDefaultValue() Option
WithDefaultValue valid when the field in dst is a type-specific default value.
func WithIgnoreFields ¶ added in v0.0.4
func WithIgnoreSourceDefaultValue ¶ added in v0.0.4
func WithIgnoreSourceDefaultValue() Option
WithIgnoreSourceDefaultValue not valid if the src field is a type-specific default value.
func WithTargetFields ¶ added in v0.0.4
Click to show internal directories.
Click to hide internal directories.