blackmagic

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 2 Imported by: 19

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")

func InvalidValueError added in v1.0.3

func InvalidValueError() error

InvalidValueError is a sentinel error that can be used to indicate that a value is invalid. This can happen when the source value is an untyped nil, and we have no further information about the type of the value, obstructing the assignment.

Types

This section is empty.

Jump to

Keyboard shortcuts

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