Help us shape the future of Go! Take the 2026 Go Developer Survey

schema

package
v0.12.8 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Rules = map[string][]FieldRule{
	"Article": {
		{Field: "headline", Level: LevelError, Message: "Missing required field 'headline'"},
		{Field: "image", Level: LevelError, Message: "Missing required field 'image'"},
		{Field: "datePublished", Level: LevelError, Message: "Missing required field 'datePublished'"},
		{Field: "author", Level: LevelError, Message: "Missing required field 'author'"},
		{Field: "dateModified", Level: LevelWarning, Message: "Recommended field 'dateModified' is missing"},
		{Field: "publisher", Level: LevelWarning, Message: "Recommended field 'publisher' is missing"},
	},
	"NewsArticle": {
		{Field: "headline", Level: LevelError, Message: "Missing required field 'headline'"},
		{Field: "image", Level: LevelError, Message: "Missing required field 'image'"},
		{Field: "datePublished", Level: LevelError, Message: "Missing required field 'datePublished'"},
		{Field: "author", Level: LevelError, Message: "Missing required field 'author'"},
		{Field: "dateModified", Level: LevelWarning, Message: "Recommended field 'dateModified' is missing"},
	},
	"BlogPosting": {
		{Field: "headline", Level: LevelError, Message: "Missing required field 'headline'"},
		{Field: "image", Level: LevelError, Message: "Missing required field 'image'"},
		{Field: "datePublished", Level: LevelError, Message: "Missing required field 'datePublished'"},
		{Field: "author", Level: LevelError, Message: "Missing required field 'author'"},
	},
	"Product": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "image", Level: LevelError, Message: "Missing required field 'image'"},
		{Field: "offers", Level: LevelWarning, Message: "Recommended field 'offers' is missing"},
		{Field: "offers.price", Level: LevelWarning, Message: "Recommended field 'offers.price' is missing"},
		{Field: "offers.priceCurrency", Level: LevelWarning, Message: "Recommended field 'offers.priceCurrency' is missing"},
		{Field: "offers.availability", Level: LevelWarning, Message: "Recommended field 'offers.availability' is missing"},
		{Field: "review", Level: LevelWarning, Message: "Recommended field 'review' is missing"},
		{Field: "aggregateRating", Level: LevelWarning, Message: "Recommended field 'aggregateRating' is missing"},
		{Field: "brand", Level: LevelWarning, Message: "Recommended field 'brand' is missing"},
		{Field: "description", Level: LevelWarning, Message: "Recommended field 'description' is missing"},
		{Field: "sku", Level: LevelWarning, Message: "Recommended field 'sku' is missing"},
	},
	"FAQPage": {
		{Field: "mainEntity", Level: LevelError, Message: "Missing required field 'mainEntity'"},
	},
	"HowTo": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "step", Level: LevelError, Message: "Missing required field 'step'"},
		{Field: "image", Level: LevelWarning, Message: "Recommended field 'image' is missing"},
		{Field: "totalTime", Level: LevelWarning, Message: "Recommended field 'totalTime' is missing"},
	},
	"LocalBusiness": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "address", Level: LevelError, Message: "Missing required field 'address'"},
		{Field: "image", Level: LevelWarning, Message: "Recommended field 'image' is missing"},
		{Field: "telephone", Level: LevelWarning, Message: "Recommended field 'telephone' is missing"},
		{Field: "openingHoursSpecification", Level: LevelWarning, Message: "Recommended field 'openingHoursSpecification' is missing"},
		{Field: "geo", Level: LevelWarning, Message: "Recommended field 'geo' is missing"},
		{Field: "url", Level: LevelWarning, Message: "Recommended field 'url' is missing"},
		{Field: "priceRange", Level: LevelWarning, Message: "Recommended field 'priceRange' is missing"},
	},
	"Recipe": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "image", Level: LevelError, Message: "Missing required field 'image'"},
		{Field: "recipeIngredient", Level: LevelWarning, Message: "Recommended field 'recipeIngredient' is missing"},
		{Field: "recipeInstructions", Level: LevelWarning, Message: "Recommended field 'recipeInstructions' is missing"},
		{Field: "cookTime", Level: LevelWarning, Message: "Recommended field 'cookTime' is missing"},
		{Field: "nutrition", Level: LevelWarning, Message: "Recommended field 'nutrition' is missing"},
		{Field: "aggregateRating", Level: LevelWarning, Message: "Recommended field 'aggregateRating' is missing"},
	},
	"Event": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "startDate", Level: LevelError, Message: "Missing required field 'startDate'"},
		{Field: "location", Level: LevelError, Message: "Missing required field 'location'"},
		{Field: "image", Level: LevelWarning, Message: "Recommended field 'image' is missing"},
		{Field: "description", Level: LevelWarning, Message: "Recommended field 'description' is missing"},
		{Field: "endDate", Level: LevelWarning, Message: "Recommended field 'endDate' is missing"},
		{Field: "offers", Level: LevelWarning, Message: "Recommended field 'offers' is missing"},
		{Field: "performer", Level: LevelWarning, Message: "Recommended field 'performer' is missing"},
		{Field: "organizer", Level: LevelWarning, Message: "Recommended field 'organizer' is missing"},
	},
	"BreadcrumbList": {
		{Field: "itemListElement", Level: LevelError, Message: "Missing required field 'itemListElement'"},
	},
	"VideoObject": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "description", Level: LevelError, Message: "Missing required field 'description'"},
		{Field: "thumbnailUrl", Level: LevelError, Message: "Missing required field 'thumbnailUrl'"},
		{Field: "uploadDate", Level: LevelError, Message: "Missing required field 'uploadDate'"},
		{Field: "contentUrl", Level: LevelWarning, Message: "Recommended field 'contentUrl' is missing"},
		{Field: "duration", Level: LevelWarning, Message: "Recommended field 'duration' is missing"},
		{Field: "embedUrl", Level: LevelWarning, Message: "Recommended field 'embedUrl' is missing"},
	},
	"Review": {
		{Field: "itemReviewed", Level: LevelError, Message: "Missing required field 'itemReviewed'"},
		{Field: "author", Level: LevelError, Message: "Missing required field 'author'"},
		{Field: "reviewRating", Level: LevelWarning, Message: "Recommended field 'reviewRating' is missing"},
		{Field: "datePublished", Level: LevelWarning, Message: "Recommended field 'datePublished' is missing"},
	},
	"Organization": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "url", Level: LevelWarning, Message: "Recommended field 'url' is missing"},
		{Field: "logo", Level: LevelWarning, Message: "Recommended field 'logo' is missing"},
		{Field: "contactPoint", Level: LevelWarning, Message: "Recommended field 'contactPoint' is missing"},
		{Field: "sameAs", Level: LevelWarning, Message: "Recommended field 'sameAs' is missing"},
	},
	"Person": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "url", Level: LevelWarning, Message: "Recommended field 'url' is missing"},
		{Field: "image", Level: LevelWarning, Message: "Recommended field 'image' is missing"},
	},
	"JobPosting": {
		{Field: "title", Level: LevelError, Message: "Missing required field 'title'"},
		{Field: "description", Level: LevelError, Message: "Missing required field 'description'"},
		{Field: "datePosted", Level: LevelError, Message: "Missing required field 'datePosted'"},
		{Field: "hiringOrganization", Level: LevelError, Message: "Missing required field 'hiringOrganization'"},
		{Field: "jobLocation", Level: LevelError, Message: "Missing required field 'jobLocation'"},
		{Field: "validThrough", Level: LevelWarning, Message: "Recommended field 'validThrough' is missing"},
		{Field: "employmentType", Level: LevelWarning, Message: "Recommended field 'employmentType' is missing"},
		{Field: "baseSalary", Level: LevelWarning, Message: "Recommended field 'baseSalary' is missing"},
	},
	"Course": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "description", Level: LevelError, Message: "Missing required field 'description'"},
		{Field: "provider", Level: LevelWarning, Message: "Recommended field 'provider' is missing"},
		{Field: "offers", Level: LevelWarning, Message: "Recommended field 'offers' is missing"},
	},
	"SoftwareApplication": {
		{Field: "name", Level: LevelError, Message: "Missing required field 'name'"},
		{Field: "offers", Level: LevelWarning, Message: "Recommended field 'offers' is missing"},
		{Field: "offers.price", Level: LevelWarning, Message: "Recommended field 'offers.price' is missing"},
		{Field: "aggregateRating", Level: LevelWarning, Message: "Recommended field 'aggregateRating' is missing"},
		{Field: "operatingSystem", Level: LevelWarning, Message: "Recommended field 'operatingSystem' is missing"},
		{Field: "applicationCategory", Level: LevelWarning, Message: "Recommended field 'applicationCategory' is missing"},
	},
}

Rules maps Google-supported schema types to their validation rules. Error = required by Google, Warning = recommended.

Functions

func CountSummary

func CountSummary(items []StructuredDataItem) (valid, errors, warnings uint16)

CountSummary returns (validCount, errorCount, warningCount) from items.

Types

type FieldRule

type FieldRule struct {
	Field   string          // JSON path: "headline", "offers.price"
	Level   ValidationLevel // "error" or "warning"
	Message string
}

FieldRule defines a required or recommended field for a schema type.

type StructuredDataItem

type StructuredDataItem struct {
	CrawlSessionID string
	URL            string
	SchemaType     string
	JSONLD         string
	Errors         []string
	Warnings       []string
	IsValid        bool
	Source         string // "static" or "rendered"
	CrawledAt      time.Time
}

StructuredDataItem is the storage-ready form of a validated structured data block.

func ValidateAllBlocks

func ValidateAllBlocks(blocks []string, sessionID, url string, crawledAt time.Time, source string) []StructuredDataItem

ValidateAllBlocks validates multiple JSON-LD blocks and returns storage-ready items.

type ValidationIssue

type ValidationIssue struct {
	Level   ValidationLevel `json:"level"`
	Message string          `json:"message"`
}

ValidationIssue represents a single validation error or warning.

type ValidationLevel

type ValidationLevel string

ValidationLevel indicates severity of a validation issue.

const (
	LevelError   ValidationLevel = "error"
	LevelWarning ValidationLevel = "warning"
)

type ValidationResult

type ValidationResult struct {
	SchemaType string            `json:"schema_type"`
	RawJSON    string            `json:"raw_json"`
	Errors     []ValidationIssue `json:"errors"`
	Warnings   []ValidationIssue `json:"warnings"`
	IsValid    bool              `json:"is_valid"`
}

ValidationResult holds the validation outcome for one structured data item.

func ValidateBlock

func ValidateBlock(jsonLD string) []ValidationResult

ValidateBlock parses a single JSON-LD block and validates all items within it.

Jump to

Keyboard shortcuts

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