package zreflect
import "zgo.at/zstd/zreflect"
Package zreflect implements functions for reflection.
Index ¶
- func Fields(t any, tagname, skip string) (names []string, vals []any, opts [][]string)
- func Names(t any, tagname, skip string) []string
- func Tag(field reflect.StructField, tag string) (string, []string)
- func Values(t any, tagname, skip string) []any
Functions ¶
func Fields ¶
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 ¶
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 ¶
Values is like Fields, but only returns the values.
Source Files ¶
zreflect.go
- Version
- v0.0.0-20240930202209-a63c3335042a (latest)
- Published
- Sep 30, 2024
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 2 days ago –
Tools for package owners.