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"`
}
| Field | Type | Description |
|---|---|---|
ReflectType | reflect.Type | Actual reflect.Type (excluded from JSON) |
FQDN | string | Fully qualified type name (e.g., "github.com/you/app/models.User") |
TypeName | string | Short type name (e.g., "User") |
PackageName | string | Full package path (e.g., "github.com/you/app/models") |
Fields | []FieldMetadata | All exported fields |
Relationships | []TypeRelationship | References 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"`
}
| Field | Type | Description |
|---|---|---|
Index | []int | Field index path for reflect.Value.FieldByIndex() |
Name | string | Field name (e.g., "Email") |
Type | string | Go type as string (e.g., "string", "*Profile", "[]Order") |
Kind | FieldKind | Type category (see below) |
ReflectType | reflect.Type | Actual reflect.Type for programmatic use (excluded from JSON) |
Tags | map[string]string | All 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"`
}
| Field | Type | Description |
|---|---|---|
From | string | Source type FQDN (e.g., "github.com/you/app/models.User") |
To | string | Target type FQDN (e.g., "github.com/you/app/models.Profile") |
Field | string | Field that creates the relationship |
Kind | string | Relationship kind (see below) |
ToPackage | string | Target 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.