Documentation
¶
Overview ¶
Package manifest implements the Radio 2.0 station manifest, live events and schedule document (SPECIFICATION.md sections 2, 5, 6, 7, 8 and 10), including the over-the-air description of section 2.6.
The types mirror schema/*.schema.json. Parse and ParseEvent decode strictly; Validate checks a document against the embedded schemas and the rules a schema cannot express; Normalize applies the spec's defaults.
Index ¶
- Constants
- Variables
- func IsCountry(code string) bool
- func IsDevelopmentAddr(ip netip.Addr) bool
- func IsDevelopmentHost(host string) bool
- func IsDevelopmentURL(raw string) bool
- func KnownPlatform(token string) bool
- type Address
- type Branding
- type Broadcast
- type Contact
- type Coverage
- type Event
- type Events
- type Info
- type Item
- type Location
- type Manifest
- type Options
- type ParseError
- type Problem
- type RDS
- type Recipient
- type RegulatorID
- type Report
- type Schedule
- type ScheduleItem
- type ScheduleRef
- type ServedArea
- type Severity
- type Show
- type Site
- type SocialLink
- type Stream
- type Tier
- type Transmission
- type Value
- type VideoStream
Constants ¶
const ( ModeOnAir = "on_air" ModeWebOnly = "web_only" )
Broadcast modes (section 2.6).
const ( BandFM = "fm" BandAM = "am" BandLW = "lw" BandSW = "sw" BandHDFM = "hd_fm" BandHDAM = "hd_am" BandDAB = "dab" BandDABPlus = "dab_plus" BandDRM = "drm" BandDRMPlus = "drm_plus" BandSatellite = "satellite" BandCable = "cable" BandDTV = "dtv" )
Bands (section 2.6). BandAM is medium wave.
const ( MaxManifestBytes = 256 << 10 MaxEventBytes = 64 << 10 MaxScheduleBytes = 256 << 10 )
Size limits from sections 2.1, 5.1 and 10.2.
const ( TypeNowPlaying = "now_playing" TypeShowChange = "show_change" TypeLiveStart = "live_start" TypeLiveEnd = "live_end" TypeScheduleChange = "schedule_change" TypeValueChange = "value_change" TypeHeartbeat = "heartbeat" )
Event types (section 5.2).
const CarriesWeb = "web"
CarriesWeb is the value of Stream.Carries for an internet-only stream.
const DefaultPollInterval = 15
DefaultPollInterval is the events.pollInterval default (section 5.1), seconds.
const SpecVersion = "0.2"
SpecVersion is the value of the specVersion member this package implements.
Variables ¶
var ( ErrTooLarge = errors.New("document exceeds the size limit") ErrNotUTF8 = errors.New("document is not valid UTF-8") ErrNotObject = errors.New("document is not a single JSON object") ErrTrailing = errors.New("unexpected data after the JSON object") )
Errors returned by the Parse functions.
var ExampleGUIDs = []string{
"9b2f6c1e-4d3a-5b8e-9f10-2a6c7d8e9f01",
"3f0c9a52-7e1b-5d24-8c6a-0b9e4f2d7a13",
"6d1e2f30-8a4b-5c6d-9e7f-1a2b3c4d5e6f",
"0e9d8c7b-6a5f-4e3d-8c2b-1a0f9e8d7c6b",
}
ExampleGUIDs are the guids of the specification's examples. They are for documentation only; a manifest that uses one gets a warning (section 4.1).
var Platforms = []string{"facebook", "instagram", "x", "threads", "tiktok", "youtube", "bluesky", "mastodon",
"linkedin", "snapchat", "telegram", "whatsapp_channel", "discord", "twitch", "spotify", "apple_podcasts",
"soundcloud", "mixcloud", "website", "other"}
Platforms are the RECOMMENDED contact.social platform tokens (section 7).
Functions ¶
func IsCountry ¶
IsCountry reports whether code is an officially assigned ISO 3166-1 alpha-2 code, in upper case. Reserved codes such as EU and UK are not.
func IsDevelopmentAddr ¶
IsDevelopmentAddr reports whether ip is a loopback or private address of the development tier.
func IsDevelopmentHost ¶
IsDevelopmentHost reports whether host (a host name or IP literal, without port) is one of the development-tier hosts of section 10.2: localhost, *.localhost, *.local, *.internal, *.test, loopback addresses, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and fc00::/7.
func IsDevelopmentURL ¶
IsDevelopmentURL reports whether the URL's host is a development host.
func KnownPlatform ¶
KnownPlatform reports whether token is one of Platforms.
Types ¶
type Address ¶
type Address struct {
Label string `json:"label,omitempty"`
Street string `json:"street,omitempty"`
Locality string `json:"locality,omitempty"`
Region string `json:"region,omitempty"`
PostalCode string `json:"postalCode,omitempty"`
Country string `json:"country,omitempty"`
}
Address is contact.address: a postal address for display and contact only, never for ranking or verification (section 7). Street lines are separated by "\n".
type Branding ¶
type Branding struct {
Logo string `json:"logo,omitempty"`
Icon string `json:"icon,omitempty"`
Banner string `json:"banner,omitempty"`
ThemeColor string `json:"themeColor,omitempty"`
}
Branding is section 2.3.
type Broadcast ¶
type Broadcast struct {
Mode string `json:"mode"`
Transmissions []Transmission `json:"transmissions,omitempty"`
RegulatorIDs []RegulatorID `json:"regulatorIds,omitempty"`
}
Broadcast says whether and how the station is on the air (section 2.6).
type Contact ¶
type Contact struct {
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
WhatsApp string `json:"whatsapp,omitempty"`
RequestsURL string `json:"requestsUrl,omitempty"`
Address *Address `json:"address,omitempty"`
Social []SocialLink `json:"social,omitempty"`
}
Contact is section 7.
type Event ¶
type Event struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
SentAt time.Time `json:"sentAt"`
Item *Item `json:"item,omitempty"`
Live *bool `json:"live,omitempty"`
OnAir *bool `json:"onAir,omitempty"`
Show *Show `json:"show,omitempty"`
Listeners *int `json:"listeners,omitempty"`
Value *Value `json:"value,omitempty"`
}
Event is one live event (section 5). Which members are meaningful depends on Type; the schema rejects the rest. A nil Show or Value means JSON null (or absent where the member is optional).
func ParseEvent ¶
ParseEvent decodes one live event strictly (at most 64 KiB, section 5.1).
type Events ¶
type Events struct {
SSE string `json:"sse"`
Poll string `json:"poll"`
PollInterval int `json:"pollInterval,omitempty"`
}
Events holds the live event addresses (section 5.1). PollInterval is in seconds; 0 means "not given" (the default is 15, see Normalize).
type Info ¶
type Info struct {
// Tier is the security tier the manifest's addresses fall in.
Tier Tier
// DefaultStream is the id of the stream a player opens first.
DefaultStream string
// Changes describes each adjustment made, for display.
Changes []string
}
Info reports what Normalize decided.
func Normalize ¶
Normalize applies the spec's normalisation rules in place (section 2.5):
- exactly one default stream (section 2.4): with none, the first stream is the default; with several, the first keeps the flag and the others lose it;
- the same rule among the video streams (section 9);
- events.pollInterval defaults to 15 seconds (section 5.1);
- the security tier is determined (section 10.2).
type Item ¶
type Item struct {
Kind string `json:"kind"`
Title string `json:"title"`
Artists []string `json:"artists,omitempty"`
Album string `json:"album,omitempty"`
Year int `json:"year,omitempty"`
Artwork string `json:"artwork,omitempty"`
ISRC string `json:"isrc,omitempty"`
URL string `json:"url,omitempty"`
StartedAt time.Time `json:"startedAt"`
DurationMs *int64 `json:"durationMs"`
}
Item is the current item of a now_playing event (section 5.3).
type Location ¶
type Location struct {
City string `json:"city,omitempty"`
Region string `json:"region,omitempty"`
}
Location is the optional city and region (section 2.2).
type Manifest ¶
type Manifest struct {
SpecVersion string `json:"specVersion"`
GUID string `json:"guid"`
ManifestURL string `json:"manifestUrl"`
Locked bool `json:"locked,omitempty"`
Name string `json:"name"`
Tagline string `json:"tagline,omitempty"`
Description string `json:"description,omitempty"`
Homepage string `json:"homepage"`
Language string `json:"language"`
Country string `json:"country,omitempty"`
Location *Location `json:"location,omitempty"`
Genres []string `json:"genres,omitempty"`
Branding *Branding `json:"branding,omitempty"`
Streams []Stream `json:"streams"`
Broadcast *Broadcast `json:"broadcast,omitempty"`
Events *Events `json:"events,omitempty"`
Schedule *ScheduleRef `json:"schedule,omitempty"`
Contact *Contact `json:"contact,omitempty"`
Value *Value `json:"value,omitempty"`
VideoStreams []VideoStream `json:"videoStreams,omitempty"`
Extensions map[string]any `json:"extensions,omitempty"`
}
Manifest is a station manifest (section 2.2).
func Parse ¶
Parse decodes a manifest strictly: the document must be one UTF-8 JSON object of at most 256 KiB, and a member the schema does not define (outside "extensions") is an error, as the manifest schema forbids it (section 2.1). Parse does not apply the schema's value rules; call Validate for that. A consumer that must tolerate later minor versions uses ParseLenient.
func ParseLenient ¶
ParseLenient is Parse for consumers: members it does not know are ignored ("A consumer MUST ignore members it does not know", section 2.1).
func (*Manifest) DefaultStream ¶
DefaultStream returns the stream a player opens first without changing m.
func (*Manifest) OnAir ¶
OnAir derives the station-level summary of section 2.6. known is false when the manifest says nothing. The streams win over broadcast.mode: a stream that carries a listed transmission makes the station on the air.
func (*Manifest) StreamCarries ¶
func (m *Manifest) StreamCarries(s *Stream) (txs []*Transmission, web bool)
StreamCarries reports what stream s carries: the transmissions it is the feed of, or web true for an internet-only stream. Both empty means unspecified. Ids that name no transmission are skipped, as a consumer does.
func (*Manifest) Tier ¶
Tier returns Development when any of manifestUrl, homepage, events or schedule addresses is plain http or names a development host, else Production. A development manifest is never verified for a public listing.
func (*Manifest) Transmission ¶
func (m *Manifest) Transmission(id string) *Transmission
Transmission returns the transmission with id, or nil.
type Options ¶
type Options struct {
// Tier Production (the zero value) requires https wherever the spec says
// MUST. Development also allows http for development hosts.
Tier Tier
}
Options select the security tier checks of section 10.2.
type ParseError ¶
type ParseError struct{ Err error }
ParseError wraps a decoding failure.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type Problem ¶
type Problem struct {
Pointer string `json:"pointer"`
Message string `json:"message"`
Rule string `json:"rule"` // "schema", "syntax", "size" or a semantic rule name
Severity Severity `json:"severity"`
}
Problem is one finding, located by an RFC 6901 JSON pointer.
type Recipient ¶
type Recipient struct {
Name string `json:"name,omitempty"`
Type string `json:"type"`
Address string `json:"address"`
Split int `json:"split"`
Fee bool `json:"fee,omitempty"`
CustomKey string `json:"customKey,omitempty"`
CustomValue string `json:"customValue,omitempty"`
Role string `json:"role,omitempty"`
}
Recipient is one payee of a Value block.
type RegulatorID ¶
type RegulatorID struct {
Authority string `json:"authority"`
Kind string `json:"kind,omitempty"`
ID string `json:"id"`
}
RegulatorID is an identifier issued by a broadcasting authority. Authority is "<country>.<authority>", for example "us.fcc" or "gb.ofcom".
type Report ¶
type Report struct {
Problems []Problem
}
Report is the outcome of a validation.
func Validate ¶
Validate checks a manifest document against the embedded JSON Schema and the rules a schema cannot express: unique stream ids, a positive split sum, https requirements with the development exemptions, a usable schedule and time zone. Semantic rules run only when the schema check passes.
func ValidateEvent ¶
ValidateEvent checks one event document against event.schema.json, selecting the definition by the event's type, then the semantic rules.
func ValidateManifest ¶
ValidateManifest applies only the semantic rules to an already decoded manifest. Validate calls it after the schema passes.
func ValidateSchedule ¶
ValidateSchedule checks a schedule document (section 6).
type Schedule ¶
type Schedule struct {
TimeZone string `json:"timeZone"`
Items []ScheduleItem `json:"items"`
}
Schedule is the document at schedule.json (section 6).
func ParseSchedule ¶
ParseSchedule decodes a schedule document strictly.
type ScheduleItem ¶
type ScheduleItem struct {
ID string `json:"id,omitempty"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Presenters []string `json:"presenters,omitempty"`
Live *bool `json:"live,omitempty"`
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
URL string `json:"url,omitempty"`
Artwork string `json:"artwork,omitempty"`
}
ScheduleItem is one programme of a Schedule.
type ScheduleRef ¶
type ScheduleRef struct {
TimeZone string `json:"timeZone"`
JSON string `json:"json,omitempty"`
ICal string `json:"ical,omitempty"`
}
ScheduleRef is the manifest's schedule member (section 6).
type ServedArea ¶
type ServedArea struct {
City string `json:"city,omitempty"`
Region string `json:"region,omitempty"`
Country string `json:"country,omitempty"`
}
ServedArea is the place a transmission serves.
type Show ¶
type Show struct {
Title string `json:"title"`
Presenters []string `json:"presenters,omitempty"`
StartsAt *time.Time `json:"startsAt,omitempty"`
EndsAt *time.Time `json:"endsAt,omitempty"`
URL string `json:"url,omitempty"`
}
Show is a programme (section 5.3).
type SocialLink ¶
type SocialLink struct {
Platform string `json:"platform,omitempty"`
Label string `json:"label,omitempty"`
URL string `json:"url"`
}
SocialLink is one entry of contact.social. Platform is a token such as "instagram" (see Platforms); unknown tokens are allowed.
func (SocialLink) DisplayName ¶
func (l SocialLink) DisplayName() string
DisplayName is what a consumer shows for the link when it does not know the platform: the label, else the URL's host (section 7).
type Stream ¶
type Stream struct {
ID string `json:"id"`
URL string `json:"url"`
MimeType string `json:"mimeType"`
Protocol string `json:"protocol,omitempty"`
Bitrate int `json:"bitrate,omitempty"`
SampleRate int `json:"sampleRate,omitempty"`
Channels int `json:"channels,omitempty"`
TypicalDelayMs *int `json:"typicalDelayMs,omitempty"`
Default bool `json:"default,omitempty"`
// Carries names the transmissions this stream is the feed of, or is
// []string{CarriesWeb} for an internet-only stream; nil is unspecified
// (section 2.6).
Carries []string `json:"carries,omitempty"`
}
Stream is an audio stream (section 2.4).
type Transmission ¶
type Transmission struct {
ID string `json:"id"`
Band string `json:"band"`
FrequencyKhz int `json:"frequencyKhz,omitempty"`
FrequencyMhz float64 `json:"frequencyMhz,omitempty"`
Subchannel int `json:"subchannel,omitempty"`
Block string `json:"block,omitempty"`
Channel string `json:"channel,omitempty"`
Provider string `json:"provider,omitempty"`
CallSign string `json:"callSign,omitempty"`
LicensedName string `json:"licensedName,omitempty"`
ECC string `json:"ecc,omitempty"`
RDS *RDS `json:"rds,omitempty"`
ServiceID string `json:"serviceId,omitempty"`
EnsembleID string `json:"ensembleId,omitempty"`
Area *ServedArea `json:"area,omitempty"`
Coverage *Coverage `json:"coverage,omitempty"`
Site *Site `json:"site,omitempty"`
RegulatorIDs []RegulatorID `json:"regulatorIds,omitempty"`
}
Transmission is one over-the-air (or satellite, cable or TV) service.
func (Transmission) Label ¶
func (t Transmission) Label() string
Label is the short text a directory shows for a transmission (section 2.6), for example "102.7 FM WXYZ", "102.7 HD2 WXYZ", "DAB+ 11B Harbourside Radio" or "SiriusXM 23".
type Value ¶
type Value struct {
Type string `json:"type"`
Method string `json:"method"`
Suggested string `json:"suggested,omitempty"`
Recipients []Recipient `json:"recipients"`
}
Value is the listener-support block (section 8.1).
type VideoStream ¶
type VideoStream struct {
ID string `json:"id"`
URL string `json:"url"`
MimeType string `json:"mimeType"`
Protocol string `json:"protocol"`
Kind string `json:"kind,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
FrameRate int `json:"frameRate,omitempty"`
SyncStreamID string `json:"syncStreamId,omitempty"`
TypicalDelayMs *int `json:"typicalDelayMs,omitempty"`
Default bool `json:"default,omitempty"`
}
VideoStream is a visual-radio stream (section 9).