The library declares Go types of https://schema.org ontology.
Schema.org is a collaborative, community activity with a mission to create, maintain, and promote schemas for structured data on the Internet, on web pages, in email messages, and beyond.
The common vocabulary layouts content into data structure interpretable by human and machines. It also guarantees an interoperability baseline for software in the distribute systems, in the absence of strong content negotiation techniques. Despite, the scheme.org elevates creation of web structured data markup schema, it also defines an ontology usable for data design in other context such as public RESTful interfaces, gRPC or GraphQL.
A core principle of the schema.org vocabulary is to indicate an entity type. As an example, the vocabulary defines a rich collection of rdf:Property
, which are essential building blocks for product types.
type Person struct {
schemaorg.FamilyName `json:"schema:familyName"`
}
The latest version of the library is available at its main
branch. All development, including new features and bug fixes, take place on the main
branch using forking and pull requests as described in contribution guidelines. The stable version is available via Golang modules.
The library uses semver schema, the minor version identifies the https://schema.org release used to generate types. For example, the version v1.14.0 of the library is built from release 14.0. The patch version is just a sequential number, increased every time this library is fixed or updated, it do not have any correlation with https://schema.org release.
Ontologies use rdf:Property
to depict characteristic of entities, which differs significantly from Golang type system. Instead of defining product type in terms of named properties, ontologies describe properties in terms of types to which they apply, which allows to extends concepts, defining additional properties without the need to re-define the original description of types.
rdf:Property
is a relation between subject resources and object resources. The concept of property at Go programming languages does not correspond to the rdf:Property
, with an exception that "properties" of structs has names and corresponding types.
/*
The statement
Person schema:familyName "Doe"
*/
type Person struct {
schemaorg.FamilyName `json:"schema:familyName"`
}
Type-level meta-programming helps us better reflect the rdf:Property
concept but type-level programming is not supported at Golang. Therefore, this library reflects the rdf:Property
to the type.
/*
{
"@id": "schema:familyName",
"@type": "rdf:Property",
"rdfs:comment": "Family name. In the U.S., the last name of a Person.",
"rdfs:label": "familyName",
...
}
*/
type FamilyName string
So that, the application "assembles" core domain type as a product of the types defined by schema.org
import "github.com/fogfish/schemaorg"
type Person struct {
schemaorg.Identifier `json:"schema:@id"`
schemaorg.GivenName `json:"schema:givenName"`
schemaorg.FamilyName `json:"schema:familyName"`
schemaorg.Email `json:"schema:email"`
}
The library is auto-generated from schema.org JSON-LD definition using schemacli utility.
Use the following commands to re-generate the type definitions
- Install command-line
go install github.com/fogfish/schemacli@latest
- Download the latest release of schema.org
curl -O https://raw.githubusercontent.com/schemaorg/schemaorg/refs/heads/main/data/releases/28.0/schemaorg-all-http.jsonld
- Generate Golang types
schemacli property -f schemaorg-all-http.jsonld > types.go
If you experience any issues with the library or requires a new feature, please let us know via GitHub issues.