reflectutil

package
v0.85.0-pre.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 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 := reflect.TypeFor[io.Reader]()
if reflectutil.DoesTypeImplementInterface(t, readerIface) {
	// supports io.Reader
}

DoesTypeImplementInterface 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.JSONFieldName(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 JSONFieldName(field reflect.StructField) string
  • func DoesTypeImplementInterface(t reflect.Type, iface reflect.Type) bool

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoesTypeImplementInterface

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

DoesTypeImplementInterface reports whether t implements iface, accounting for both value and pointer receiver method sets.

It returns false when t or iface is nil. It panics when iface is not an interface type; this panic enforces the developer invariant that callers must pass an actual interface type for iface.

func ExcludingNoneGetIsNilOrUltimatelyPointsToNil

func ExcludingNoneGetIsNilOrUltimatelyPointsToNil(v any) bool

func JSONFieldName

func JSONFieldName(field reflect.StructField) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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