...

Package blackmagic

import "github.com/lestrrat-go/blackmagic"
Overview
Index

Overview ▾

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

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