reflection

package
v1.62.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Overview

* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStructField

func GetStructField(structure interface{}, fieldName string) (interface{}, bool)

GetStructField checks if the given structure has a given field. The structure should be passed by reference. It returns an interface and a boolean, the field's content and a boolean denoting whether or not the field exists. If the boolean is false then there is no such field on the structure. If the boolean is true but the interface stores "" then the field exists but is not set. If the boolean is true and the interface is not emtpy, the field exists and is set.

func GetStructureField

func GetStructureField(field reflect.Value) interface{}

func GetUnexportedStructureField

func GetUnexportedStructureField(structure interface{}, fieldName string) interface{}

func InheritsFrom

func InheritsFrom(object interface{}, parentType reflect.Type) bool

InheritsFrom uses reflection to find if a struct "inherits" from a certain type. In other words it checks whether the struct embeds a struct of that type.

func IsEmpty added in v1.4.2

func IsEmpty(value interface{}) bool

IsEmpty checks whether a value is empty i.e. "", nil, 0, [], {}, false, etc.

func SetStructField

func SetStructField(structure interface{}, fieldName string, value interface{}) error

SetStructField attempts to set a field of a structure to the given vaule It returns nil or an error, in case the field doesn't exist on the structure or the value and the field have different types

func SetStructureField

func SetStructureField(field reflect.Value, value interface{})

func SetUnexportedStructureField

func SetUnexportedStructureField(structure interface{}, fieldName string, value interface{})

func ToStructPtr added in v1.8.0

func ToStructPtr(obj reflect.Value) (val interface{}, err error)

ToStructPtr returns an instance of the pointer (interface) to the object obj.

Types

This section is empty.

Jump to

Keyboard shortcuts

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