dark

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnsafeDisabled is a build-time constant which specifies whether or
	// not access to the unsafe package is available.
	UnsafeDisabled = false
)

Variables

View Source
var GetInterface = func(val reflect.Value, force bool) (any, bool) {
	if !val.IsValid() {
		return nil, true
	}

	if val.CanInterface() {
		return val.Interface(), true
	}

	if force {
		val = unsafeReflectValue(val)
		if val.CanInterface() {
			return val.Interface(), true
		}
	}

	copyVal, ok := CopyValue(val)
	if ok && copyVal.CanInterface() {
		return copyVal.Interface(), true
	}

	return nil, false
}

GetInterface does its best to return the data behind val. If force is true, it tries to bypass golang protections using the unsafe package.

It returns (nil, false) if the data behind val can not be retrieved as an any interface (aka struct private + non-copyable field).

Functions

func CopyValue

func CopyValue(val reflect.Value) (reflect.Value, bool)

CopyValue does its best to copy val in a new reflect.Value instance.

func MustGetInterface

func MustGetInterface(val reflect.Value) any

MustGetInterface does its best to return the data behind val. If it fails (struct private + non-copyable field), it panics.

Types

This section is empty.

Jump to

Keyboard shortcuts

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