Releases: aafeher/go-microdata-extract
Releases · aafeher/go-microdata-extract
Release list
v0.12.0
What's Changed in v0.12.0
Added
ConfigErrorstructured error type (Field string,Err error) — returned byExtract()before any network call when the Extractor is misconfigured (e.g.fetchTimeoutis 0 without a custom HTTP client, ormaxBodySize≤ 0); supportserrors.Asanderrors.Unwrap- Configuration getter methods:
GetUserAgent() string,GetFetchTimeout() uint8,GetHTTPClient() *http.Client,GetMaxBodySize() int64,GetSyntaxes() []Syntax— allow callers to inspect the active configuration;GetSyntaxes()returns a copy to prevent external mutation SetMaxBodySize(size int64) *Extractor— caps the number of bytes read from an HTTP response body viaio.LimitReader; responses exceeding the limit are rejected with aFetchError; default is 10 MB- URL scheme validation at the start of
Extract()— non-http/httpsschemes (e.g.javascript:,file:,data:) are rejected immediately with aFetchErrorbefore any HTTP client call - Relative URL resolution in
ParseRDFa—href,src, andresourceattribute values are now resolved against the page base URL (theURLparameter was previously discarded) - Relative URL resolution in
ParseMicroformats—u-*property values (href,src,data,action) are now resolved against the page base URL (theURLparameter was previously discarded) - Relative URL resolution in
ParseJSONLD—@idandurlfield values are now resolved against the page base URL (theURLparameter was previously discarded); resolution is applied recursively to nested objects and arrays - Package-level godoc:
// Package extract …inextract.goand// Package extractor …inextractors/doc.go - Godoc comments added to previously undocumented public functions:
ParseJSONLD,ParseW3CMicrodata,ParseMicroformats - New examples:
getconfiguration,getxcards,sethttpclient,setmaxbodysize,getextractedjson errorhandlingexample extended with aConfigErrorscenario
Changed
- API: extractor public functions renamed to consistent
Parse*prefix —JSONLD→ParseJSONLD,W3CMicrodata→ParseW3CMicrodata,RDFa→ParseRDFa,DublinCore→ParseDublinCore,Microformats→ParseMicroformats;ParseOpenGraphandParseXCardswere already using this prefix XCardsAudio.SecureURLis now resolved against the base URL inresolveXCardsURLs()— previously onlyURLwas resolved; all other media types (XCardsImage, XCardsVideo, OpenGraphImage, OpenGraphVideo, OpenGraphAudio) already resolved both fields- Custom generic helpers
contains[]/index[]replaced with stdlibslices.Contains/slices.Index(available since Go 1.21) golang.org/x/netbumped to v0.54.0
Fixed
XCardsAudio.SecureURLwas silently left unresolved — the onlySecureURLfield across all media types not passed throughresolveURL
Full Changelog: v0.11.0...v0.12.0
v0.11.0
What's Changed in v0.11.0
Added
GetErrors() []errormethod onExtractor— exposes the accumulated parse errors from the lastExtract()call; previouslyerrswas a private field with no public getterDefaultSyntaxes() []Syntaxfunction — returns a fresh copy of the default syntax list; safe to iterate or pass toSetSyntaxeswithout risk of mutating the package-level default
Changed
Processorstruct unexported toprocessor— it was only used internally byExtract()and was never intended as part of the public APISYNTAXESexported variable replaced by unexporteddefaultSyntaxes; useDefaultSyntaxes()instead — the oldvarallowed callers to mutate the global default, causing subtle cross-call bugsFillMissingFieldsFromOpenGraphinextractors/xcards.gounexported tofillMissingFieldsFromOpenGraph— it is an internal implementation detail of the XCards extractor; corresponding tests moved fromextract_test.gotoextractors/xcards_test.go
Full Changelog: v0.10.0...v0.11.0
v0.10.0
What's Changed in v0.10.0
Added
context.Contextparameter as the first argument ofExtract()— HTTP fetches now respect context cancellation and deadline; passcontext.Background()for the previous behaviourSetHTTPClient(client *http.Client) *Extractor— injects a fully custom HTTP client (enables proxy, mutual TLS, custom transport, auth headers); when set, the client's own timeout is used instead offetchTimeoutFetchErrorstructured error type (URL string,Err error) returned byExtract()on network or non-200 failures; supportserrors.Asanderrors.UnwrapParseErrorstructured error type (Syntax Syntax,Err error) wrapping every per-extractor error accumulated inExtractor.errs; supportserrors.Asanderrors.UnwraphttpClient *http.Clientfield added to internalconfigstruct (zero value = use default client built fromfetchTimeout)
Changed
- API:
Extract(url, content)→Extract(ctx, url, content)—context.Contextis now the first parameter; all callers (examples, benchmarks, tests) updated fetch()now useshttp.NewRequestWithContextinstead ofhttp.NewRequest, propagating the caller's context to the HTTP layer- All errors returned from
fetch()are now wrapped in*FetchError; callers can useerrors.As(err, &FetchError{})to check for fetch vs parse failures - Parse errors from extractor goroutines are now wrapped in
*ParseError(tagged with the producingSyntax) before being appended toExtractor.errs errorhandlingexample updated to demonstrateerrors.Aswith*FetchError
Full Changelog: v0.9.0...v0.10.0
v0.9.0
What's Changed in v0.9.0
Changed
- Extracted shared
handleMediaSlice[T any]generic helper toextractors/shared.go— consolidates the slice-management boilerplate (append-or-reuse-last pattern) that was duplicated across all six media property handlers inopengraph.goandxcards.go - Extracted
parseMusicProperty,parseVideoObjectProperty,parseArticleProperty,parseBookProperty,parseProfilePropertytoextractors/shared.go— the five namespace-property switch blocks were identical betweenparseOpenGraphMetaTagandparseXCardsMetaTag - Moved
handleMusicSongProperty,handleVideoActorProperty,parseIntSafely,parseTimeSafelytoextractors/shared.go— these helpers are shared across multiple files and now live in a single authoritative location handleOpenGraphImageProperty,handleOpenGraphVideoProperty,handleOpenGraphAudioPropertyand their XCards counterparts are now thin wrappers overhandleMediaSlice, reducing each handler to a format-specific field-assignment closure
Full Changelog: v0.8.0...v0.9.0
v0.8.0
What's Changed in v0.8.0
Added
- RDFa error/edge-case test fixture (
test/test-55-rdfa-errors.html) — HTML with no RDFa items and a danglingpropertyattribute without atypeofparent; correspondingtest-55-rdfa-errorstest case added - Relative URL resolution test fixture (
test/test-56-opengraph-relative-urls.html) with correspondingtest-56-opengraph-relative-urlstest case verifying path-relative URLs are resolved against the page base URL resolveURL(base, ref string) stringshared helper inextractors/w3cmicrodata.gousingurl.URL.ResolveReference(handles absolute, protocol-relative, and path-relative refs correctly)resolveOpenGraphURLsinextractors/opengraph.go— resolvesog:url, image/video/audio URL and SecureURL fieldsresolveXCardsURLsinextractors/xcards.go— resolves twitter/og image/video/audio URL and SecureURL fields
Changed
- API:
ParseOpenGraphreturn type changed from(any, []error)to(*OpenGraph, []error);extract.gowrapper converts typed nil to untyped nil to preserve map semantics - API:
ParseXCardsreturn type changed from(any, []error)to(*XCards, []error); same nil handling in wrapper - API:
DublinCorereturn type changed from(any, []error)to(*DublinCoreItem, []error); same nil handling in wrapper JSONLDsignature: unused named parameterURL stringreplaced with blank identifier_ stringDublinCorelinkhrefvalues are now resolved against the page URL (previously stored verbatim)- W3CMicrodata inline URL resolution replaced with shared
resolveURL— protocol-relative URLs (//host/path) are now properly resolved tohttp://host/path; existing test updated (test-35-w3cmicrodata-book:discussionUrlvalue updated from//www.example.com/…tohttp://www.example.com/…) parseDublinCorenow accepts a URL parameter and handleshtml.ParseerrorsparseMicroformats,parseRDFa,parseW3CMicrodatanow handlehtml.Parseerrors instead of discarding them
Fixed
- Remove always-true dead condition
if len(items) >= 0inextractors/jsonld.go— simplifiedJSONLD()to returnextractJSONLD()directly - Remove no-op nil→empty-slice init blocks in
extractors/opengraph.go—handleOpenGraphImageProperty,handleOpenGraphVideoProperty,handleOpenGraphAudioPropertyeach had a redundantif len == 0 { slice = []T{} }block (Go'sappendworks identically on nil and empty slices)
Full Changelog: v0.7.0...v0.8.0
v0.7.0
What's Changed in v0.7.0
Added
- Benchmark tests (
extract_bench_test.go) for all 7 formats: OpenGraph, X Cards, JSON-LD, W3C Microdata, RDFa, Dublin Core, and Microformats, plus a combined all-syntaxes benchmark - Performance section in README with benchmark results table and instructions for running benchmarks
Full Changelog: v0.6.0...v0.7.0
v0.6.0
What's Changed in v0.6.0
Added
- Microformats2 extractor (
extractors/microformats.go) supportingh-*root items,p-*(text),u-*(URL),dt-*(datetime), ande-*(embedded HTML) property prefixes SyntaxMicroformatsconstant ("microformats") added toSYNTAXESand enabled by default- Nested item support:
h-*child nodes used as both property values andChildrenentries - Add example: Microformats extraction with recursive nested item printing (
examples/getmicroformats)
Changed
- Default syntaxes list extended with
SyntaxMicroformats - README: Microformats marked as supported in the formats table, default syntaxes updated
Full Changelog: v0.5.0...v0.6.0
v0.5.0
What's Changed in v0.5.0
Added
- Dublin Core extractor (extractors/dublincore.go) supporting DC.* and DCTERMS.* prefixes in and attributes
- SyntaxDublinCore constant ("dublincore") added to SYNTAXES and enabled by default
- Add example: Dublin Core extraction with type assertion and multiple-value handling (examples/getdublincore)
Changed
- Default syntaxes list extended with SyntaxDublinCore
- README: Dublin Core marked as supported in the formats table, default syntaxes updated
Fixed
- XCards extractor no longer falsely returns an empty struct when non-Twitter tags (e.g. Dublin Core, keywords) are present; xcHasValue is now only set for recognized twitter:, og:, music:, video:, article:, book:, or profile: prefixes
Full Changelog: v0.4.0...v0.5.0
v0.4.0
What's Changed in v0.4.0
Added
- RDFa support (
extractors/rdfa.go) — 38.9% web usagevocabandtypeofattributes for typed itemspropertyattribute for named propertiesprefixattribute with CURIE resolution (e.g.schema:Person→https://schema.org/Person)resourceandaboutattributes for subject URIs- Nested items (
property+typeofon the same element) - Sibling items (
typeof-only inside an item's subtree) - Property value resolution priority:
content→datetime→href→src→resource→ text content
SyntaxRDFaconstant ("rdfa") — enabled by default alongside the existing four syntaxes- Add example: RDFa extraction with type assertion and nested items (
examples/getrdfa)
Changed
- Default syntaxes list extended with
SyntaxRDFa - README: RDFa marked as supported in the formats table, default syntaxes updated
Full Changelog: v0.3.0...v0.4.0
v0.3.0
What's Changed in v0.3.0
Added
- Add example: raw HTML content provided directly without HTTP fetch (
examples/rawcontent) - Add example: error handling for fetch failures and missing syntax data (
examples/errorhandling) - Add example: JSON-LD extraction with type assertion and nested field access (
examples/getjsonld) - Add example: W3C Microdata extraction with type assertion and nested items (
examples/getmicrodata)
Full Changelog: v0.2.0...v0.3.0