zreflect

package
v0.0.0-...-d785515 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package zreflect implements functions for reflection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fields

func Fields(t any, tagname, skip string) (names []string, vals []any, opts [][]string)

Fields gets all exported fields for the struct t, as a slice of names, values, and tag options, in the order they are in the struct.

If tag is not an "" it will use the tag name as the field name, falling back to the field name if it's not set. Tags with a value of "-" will be skipped.

Fields will be skipped if the option given in skip is set in the tag.

It will panic if t is not a struct.

For example:

t := struct {
	One   string `db:"one"`
	Two   string `db:"two,noinsert"`
	Three int
}{"xxx", "yyy", 42}

Fields(t, "db", "noinsert")

Will return:

[]string{"one", "Three"}
[]any{"xxx", 42}
[][]string{nil, []string{"noinsert"}}

func Names

func Names(t any, tagname, skip string) []string

Names is like Fields, but only returns the names.

func Tag

func Tag(field reflect.StructField, tag string) (string, []string)

Tag splits the tag in to the tag name and options.

func Values

func Values(t any, tagname, skip string) []any

Values is like Fields, but only returns the values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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