zoobzio December 29, 2025 3 mins Edit this page

API Reference

Errors

ErrNotStruct

var ErrNotStruct = errors.New("sentinel: only struct types are supported")

Returned by TryInspect and TryScan when the type parameter is not a struct type.

Core Functions

Inspect

func Inspect[T any]() Metadata

Extracts metadata for a single type. Results are cached permanently.

Panics if T is not a struct type.

Pointer-to-struct types are automatically dereferenced. Inspect[*User]() is equivalent to Inspect[User]().

metadata := sentinel.Inspect[User]()

TryInspect

func TryInspect[T any]() (Metadata, error)

Like Inspect, but returns an error instead of panicking if T is not a struct type.

metadata, err := sentinel.TryInspect[MyType]()
if err != nil {
    // Handle non-struct type
}

Scan

func Scan[T any]() Metadata

Recursively extracts metadata for a type and all related types within the same module.

Panics if T is not a struct type.

Pointer-to-struct types are automatically dereferenced. Scan[*User]() is equivalent to Scan[User]().

metadata := sentinel.Scan[User]()
// User and all related types (Profile, Order, etc.) are now cached

TryScan

func TryScan[T any]() (Metadata, error)

Like Scan, but returns an error instead of panicking if T is not a struct type.

metadata, err := sentinel.TryScan[User]()
if err != nil {
    // Handle non-struct type
}

Tag

func Tag(tagName string)

Registers a custom struct tag for extraction. Call before Inspect or Scan.

sentinel.Tag("graphql")
sentinel.Tag("proto")

Browse

func Browse() []string

Returns all cached type FQDNs.

fqdns := sentinel.Browse()
// ["github.com/you/app/models.User", "github.com/you/app/models.Profile"]

Lookup

func Lookup(fqdn string) (Metadata, bool)

Retrieves cached metadata by FQDN.

meta, ok := sentinel.Lookup("github.com/you/app/models.User")
if ok {
    // Use meta
}

// Or use the FQDN from previously inspected metadata
userMeta := sentinel.Inspect[User]()
meta, ok = sentinel.Lookup(userMeta.FQDN)

Schema

func Schema() map[string]Metadata

Returns all cached metadata as a map, keyed by FQDN.

schema := sentinel.Schema()
for fqdn, meta := range schema {
    fmt.Printf("%s: %d fields\n", fqdn, len(meta.Fields))
}

Relationship Functions

GetRelationships

func GetRelationships[T any]() []TypeRelationship

Returns all types that T references.

rels := sentinel.GetRelationships[User]()
// [{From: "github.com/.../models.User", To: "github.com/.../models.Profile", Kind: "reference", ...}]

GetReferencedBy

func GetReferencedBy[T any]() []TypeRelationship

Returns all types that reference T. Requires prior caching of those types.

refs := sentinel.GetReferencedBy[Profile]()
// [{From: "github.com/.../models.User", To: "github.com/.../models.Profile", Kind: "reference", ...}]

Types

See Types Reference for complete type documentation: