blackmagic

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 2 Imported by: 6

README

blackmagic

Reflect-based black magic. YMMV, and use with caution

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignIfCompatible

func AssignIfCompatible(dst, src interface{}) error

AssignIfCompatible is a convenience function to safely assign arbitrary values. dst must be a pointer to an empty interface, or it must be a pointer to a compatible variable type that can hold src.

func AssignOptionalField added in v1.0.2

func AssignOptionalField(dst, src interface{}) error

AssignField is a convenience function to assign a value to an optional struct field. In Go, an optional struct field is usually denoted by a pointer to T instead of T:

type Object struct {
  Optional *T
}

This gets a bit cumbersome when you want to assign literals or you do not want to worry about taking the address of a variable.

Object.Optional = &"foo" // doesn't compile!

Instead you can use this function to do it in one line:

blackmagic.AssignOptionalField(&Object.Optionl, "foo")

Types

This section is empty.

Jump to

Keyboard shortcuts

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