Skip to content

Reference implementation

Wilkin Santana edited this page Nov 29, 2026 · 2 revisions

This article explains part of Radio 2.0 in plain words. It is not normative: where it differs from the specification, the specification is right.

The reference implementation is the Go library and command line tool kept in the Radio 2.0 repository. It validates manifests, events and schedules, finds manifests from homepages and stream URLs, and applies the verification and network rules. It is pure Go with no cgo, under the MIT licence, and there are no packaged releases or SDKs in other languages yet.

Module github.com/Tend-Stack/radio2
Packages manifest, discover, schema, and the command cmd/radio2
Spec version 0.2.4-draft
Language Go, pure Go, no cgo
Releases v0.2.4-draft and later on the releases page
Status Draft

Packages

manifest holds the types for the manifest, events and the schedule, plus these functions:

  • Parse decodes strictly. The document must be one UTF-8 JSON object within the size limit, and members the schema does not define are errors. ParseEvent and ParseSchedule do the same for those documents.
  • ParseLenient is for consumers that must ignore unknown members.
  • Validate checks a manifest document against the embedded schema and the rules a schema cannot express: unique stream ids, split sums, https and the development-host exemptions, schedule order and time zones. ValidateManifest, ValidateEvent and ValidateSchedule cover the other entry points.
  • Normalize applies the section 2.5 rules in place and returns an Info value with the tier, the default stream id and a list of changes.
  • Helpers include IsCountry, IsDevelopmentHost, IsDevelopmentURL, and methods on Manifest such as DefaultStream, Tier, OnAir, Transmission and StreamCarries.

Validate takes an Options value whose Tier field is manifest.Production (the zero value) or manifest.Development. The returned Report has OK(), Errors() and Warnings(). Each Problem carries a JSON pointer, a message, a rule name and a severity.

discover finds a manifest from a homepage (HTML link, then the well-known address) or from a stream URL (the HTTP Link header, never reading the stream body, with icy-url as a fallback). It applies the section 4 verification rule and the section 10.2 limits. discover.New(discover.Config{}) makes a client. Its methods are Discover, FromHomepage and FromStream; Verify applies the verification rule to a parsed manifest. A Result reports ManifestURL, Via (link-header, html-link or well-known), the manifest, any validation Problems and a verdict with Verified, OriginVerified and the Reasons it is not. Config sets timeout, maximum body, maximum redirects, a development switch and a user agent; the defaults are 10 seconds, 256 KiB and 5 redirects.

schema embeds the three JSON Schemas with go:embed.

cmd/radio2 is the command line tool; see radio2 command line tool.

Sample

This is the README's own sample:

rep := manifest.Validate(data, manifest.Options{})
if !rep.OK() {
	for _, p := range rep.Errors() {
		fmt.Println(p) // "/streams/1/id: stream id "main" is used more than once [unique-id]"
	}
}
res, err := discover.New(discover.Config{}).Discover(ctx, "https://radio.example.org/")
// res.ManifestURL, res.Verified

Tests

go test -race ./... runs the specification, schema and example checks. See Conformance. Discovery is tested against local httptest servers.

Other languages

There are no SDKs in other languages yet. The list of known software is on Implementations. A validator in any language can use the published JSON Schemas for the schema part, but the rules a schema cannot express need code.

See also

References

Clone this wiki locally