reflectutil

package
v0.85.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

README

kit/reflectutil

github.com/vormadev/vorma/kit/reflectutil

Small reflection helpers for interface checks, nil/pointer inspection, and JSON tag name extraction.

Import

import "github.com/vormadev/vorma/kit/reflectutil"

Quick Start

Check interface implementation (value or pointer receiver)
readerIface := reflectutil.ToInterfaceReflectType[io.Reader]()
if reflectutil.ImplementsInterface(t, readerIface) {
	// supports io.Reader
}

ImplementsInterface returns false for nil types and panics if iface is not an interface type.

Nil-or-points-to-nil checks
isNil := reflectutil.ExcludingNoneGetIsNilOrUltimatelyPointsToNil(v)

This follows pointers/interfaces recursively and treats struct{}/*struct{} ("None" sentinel) as non-nil.

JSON field name extraction
name := reflectutil.GetJSONFieldName(field)
  • returns tag name if present (json:"id,omitempty" -> id)
  • returns "" for ignored fields (json:"-")
  • falls back to field name when tag key is empty

API Coverage

Functions
  • func ExcludingNoneGetIsNilOrUltimatelyPointsToNil(v any) bool
  • func GetJSONFieldName(field reflect.StructField) string
  • func ImplementsInterface(t reflect.Type, iface reflect.Type) bool
  • func ToInterfaceReflectType[T any]() reflect.Type

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExcludingNoneGetIsNilOrUltimatelyPointsToNil

func ExcludingNoneGetIsNilOrUltimatelyPointsToNil(v any) bool

func GetJSONFieldName

func GetJSONFieldName(field reflect.StructField) string

func ImplementsInterface

func ImplementsInterface(t reflect.Type, iface reflect.Type) bool

func ToInterfaceReflectType

func ToInterfaceReflectType[T any]() reflect.Type

Types

This section is empty.

Jump to

Keyboard shortcuts

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