Documentation
¶
Overview ¶
Package structural.
Provide utility function to work with structural typing.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assign ¶
func Assign(target interface{}, sources ...interface{})
Assign every field from source to target.
Only field that exported, have same name, and same type is got assigned.
target must be pointer to a struct, and source must be struct or pointer to a struct.
Example ¶
package main
import (
"fmt"
"github.com/win-t/go-utils/structural"
)
func main() {
type aTyp struct {
A int
B string
C string
d int
}
type bTyp struct {
A int
B string
C int
d int
}
a := aTyp{1, "2", "3", 4}
b := bTyp{10, "11", 13, 14}
structural.Assign(&a, b)
fmt.Println(a.A, a.B, a.C, a.d)
}
Output: 10 11 3 4
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.