zoobzio December 29, 2025 3 mins Edit this page

Type Reference

Metadata

Complete metadata for a struct type.

type Metadata struct {
    ReflectType   reflect.Type       `json:"-"`
    FQDN          string             `json:"fqdn"`
    TypeName      string             `json:"type_name"`
    PackageName   string             `json:"package_name"`
    Fields        []FieldMetadata    `json:"fields"`
    Relationships []TypeRelationship `json:"relationships,omitempty"`
}
FieldTypeDescription
ReflectTypereflect.TypeActual reflect.Type (excluded from JSON)
FQDNstringFully qualified type name (e.g., "github.com/you/app/models.User")
TypeNamestringShort type name (e.g., "User")
PackageNamestringFull package path (e.g., "github.com/you/app/models")
Fields[]FieldMetadataAll exported fields
Relationships[]TypeRelationshipReferences to other struct types

FieldMetadata

Metadata for a single struct field.

type FieldMetadata struct {
    ReflectType reflect.Type      `json:"-"`
    Tags        map[string]string `json:"tags,omitempty"`
    Name        string            `json:"name"`
    Type        string            `json:"type"`
    Kind        FieldKind         `json:"kind"`
    Index       []int             `json:"index"`
}
FieldTypeDescription
Index[]intField index path for reflect.Value.FieldByIndex()
NamestringField name (e.g., "Email")
TypestringGo type as string (e.g., "string", "*Profile", "[]Order")
KindFieldKindType category (see below)
ReflectTypereflect.TypeActual reflect.Type for programmatic use (excluded from JSON)
Tagsmap[string]stringAll extracted struct tags

FieldKind

Type categorization for fields.

type FieldKind string

const (
    KindScalar    FieldKind = "scalar"    // string, int, float, bool, etc.
    KindPointer   FieldKind = "pointer"   // *T
    KindSlice     FieldKind = "slice"     // []T, [N]T
    KindStruct    FieldKind = "struct"    // struct types
    KindMap       FieldKind = "map"       // map[K]V
    KindInterface FieldKind = "interface" // interface{}
)

Tag Extraction

Only registered tags are extracted. Built-in tags:

  • json, db, validate, scope, encrypt, redact, desc, example

Register custom tags with sentinel.Tag(name).

TypeRelationship

A relationship between two struct types.

type TypeRelationship struct {
    From      string `json:"from"`
    To        string `json:"to"`
    Field     string `json:"field"`
    Kind      string `json:"kind"`
    ToPackage string `json:"to_package"`
}
FieldTypeDescription
FromstringSource type FQDN (e.g., "github.com/you/app/models.User")
TostringTarget type FQDN (e.g., "github.com/you/app/models.Profile")
FieldstringField that creates the relationship
KindstringRelationship kind (see below)
ToPackagestringTarget type's full package path

Relationship Kinds

const (
    RelationshipReference  = "reference"  // *Profile, Profile
    RelationshipCollection = "collection" // []Order, [5]Order
    RelationshipEmbedding  = "embedding"  // Anonymous embedded struct
    RelationshipMap        = "map"        // map[string]Item
)

JSON Serialization

All types have JSON tags for easy serialization:

schema := sentinel.Schema()
data, _ := json.MarshalIndent(schema, "", "  ")
fmt.Println(string(data))

Output:

{
  "github.com/you/app/models.User": {
    "fqdn": "github.com/you/app/models.User",
    "type_name": "User",
    "package_name": "github.com/you/app/models",
    "fields": [
      {
        "index": [0],
        "name": "ID",
        "type": "string",
        "kind": "scalar",
        "tags": {
          "json": "id",
          "db": "user_id"
        }
      },
      {
        "index": [1],
        "name": "Profile",
        "type": "*Profile",
        "kind": "pointer"
      }
    ],
    "relationships": [
      {
        "from": "github.com/you/app/models.User",
        "to": "github.com/you/app/models.Profile",
        "field": "Profile",
        "kind": "reference",
        "to_package": "github.com/you/app/models"
      }
    ]
  }
}

ReflectType is excluded from JSON serialization but available for programmatic use.