Documentation
¶
Overview ¶
Package copier allows for copying a value to a variable with an unknown type.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶
func Copy(from interface{}, to interface{}) (err error)
Copy copies a value of `from` to `to`.
from := 5 b := 0 Copy(from, &to) fmt.Println(to) // 5
Example (Err) ¶
package main
import (
"fmt"
"github.com/gomponents/gontainer-helpers/copier"
)
func main() {
var (
from float32 = 5
to uint = 0
)
err := copier.Copy(from, &to)
fmt.Println(to)
fmt.Println(err)
}
Output: 0 reflect.Set: value of type float32 is not assignable to type uint
Example (Ok) ¶
package main
import (
"fmt"
"github.com/gomponents/gontainer-helpers/copier"
)
func main() {
var (
from = 5
to = 0
)
err := copier.Copy(from, &to)
fmt.Println(to)
fmt.Println(err)
}
Output: 5 <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.