structural

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: MIT Imports: 1 Imported by: 0

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.

Jump to

Keyboard shortcuts

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