structs

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package structs provides reflection based utilities for working with structs.

structs was primarily created to provide a way to initialize a struct of string properties with the values of the property names. In this way we can mimic the ability to initialize nested consts available in other languages. It is based on reflection so does have a performance penalty however it is meant to be used as a global var or initialized with init for a one time cost

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(obj interface{}) interface{}

Init all the string fields to the names of the fields and returns a reference to the struct; panics if obj is not a non nil struct/*struct type.

Types

type Struct

type Struct struct {
	// contains filtered or unexported fields
}

Struct provides a reflection wrapper for structs

func New

func New(obj interface{}) (new *Struct)

New converts a given struct to a *Struct to work with it in reflection; panics if obj is not a non nil struct/*struct type.

func (*Struct) Fields

func (st *Struct) Fields() (fields []reflect.StructField)

Fields returns all the field names as a []string

func (*Struct) SetFieldByIndex

func (st *Struct) SetFieldByIndex(i int, value interface{}, typ ...reflect.Type)

SetFieldByIndex sets the value of the field to the given value if they are the same type; Sets private or public fields as called out by the index i. Optionially takes the value's type and the field's value.

Jump to

Keyboard shortcuts

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