copier

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 3 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL