Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultEpisodeMetadata(guid, parent string) map[string]string
- func DefaultShowMetadata(guid string) map[string]string
- func ErrorResponse(c *gin.Context, status int, err error)
- func LoadResource(data []byte) (interface{}, string, string, error)
- func StandardResponse(c *gin.Context, status int, res interface{})
- func ValidResourceName(name string) bool
- type Assertion
- type Asset
- type AuthorizationRequest
- type AuthorizationResponse
- type Build
- type Category
- type Episode
- type EpisodeDescription
- type Import
- type Metadata
- type Owner
- type Production
- type ProductionList
- type Resource
- type ResourceList
- type ResourceLoaderFunc
- type ResourceMetadata
- type Show
- type ShowDescription
- type StatusObject
- type Validatable
- type Validator
- func (v *Validator) AsError() error
- func (v *Validator) AssertContains(src map[string]string, key, name string)
- func (v *Validator) AssertError(txt string)
- func (v *Validator) AssertExistsError(src interface{}, expected string)
- func (v *Validator) AssertISO639(src string)
- func (v *Validator) AssertNotEmpty(src map[string]string, name string)
- func (v *Validator) AssertNotNil(src interface{}, name string)
- func (v *Validator) AssertNotZero(src int, name string)
- func (v *Validator) AssertStringError(src, expected string)
- func (v *Validator) AssertStringExists(src, name string)
- func (v *Validator) AssertWarning(txt string)
- func (v *Validator) Error() string
- func (v *Validator) IsClean() bool
- func (v *Validator) IsValid() bool
- func (v *Validator) NErrors() int
- func (v *Validator) NWarnings() int
- func (v *Validator) Report() string
- func (v *Validator) Validate(src Validatable) *Validator
Constants ¶
const ( // LabelLanguage ISO-639 two-letter language code. channel.language LabelLanguage = "language" // LabelExplicit ["true"|"false"] channel.itunes.explicit LabelExplicit = "explicit" // LabelType ["Episodic"|"Serial"] channel.itunes.type LabelType = "type" // LabelBlock ["Yes"] channel.itunes.block LabelBlock = "block" // LabelComplete ["Yes"] channel.itunes.complete LabelComplete = "complete" // LabelGUID resources GUID LabelGUID = "guid" // LabelParentGUID guid of the resources parent resource LabelParentGUID = "parent_guid" // LabelDate used as e.g. publish date of an episode LabelDate = "date" // LabelSeason defaults to "1" LabelSeason = "season" // LabelEpisode positive integer 1.. LabelEpisode = ResourceEpisode // ShowTypeEpisodic type of podcast is episodic ShowTypeEpisodic = "Episodic" // ShowTypeSerial type of podcast is serial ShowTypeSerial = "Serial" // EpisodeTypeFull type of episode is 'full' EpisodeTypeFull = "Full" // EpisodeTypeTrailer type of episode is 'trailer' EpisodeTypeTrailer = "Trailer" // EpisodeTypeBonus type of episode is 'bonus' EpisodeTypeBonus = "Bonus" // ResourceTypeExternal references an external URL ResourceTypeExternal = "external" // ResourceTypeLocal references a local resource ResourceTypeLocal = "local" // ResourceTypeImport references an external resources that will be imported into the CDN ResourceTypeImport = "import" // ResourceShow is referencing a resource of type "show" ResourceShow = "show" // ResourceEpisode is referencing a resource of type "episode" ResourceEpisode = "episode" // ResourceAsset is referencing any media or binary resource e.g. .mp3 or .png ResourceAsset = "asset" // ResourceALL is a wildcard for any kind of resource ResourceALL = "ALL" )
const ( // AssertionWarning indicates a potential issue AssertionWarning = 0 // AssertionError indicates an error in the validation AssertionError = 1 )
const (
// Version specifies the verion of the API and its structs
Version = "v1"
)
Variables ¶
var ( // ErrNotAuthorized indicates that the API call is not authorized ErrNotAuthorized = errors.New("api: not authorized") // ErrNoToken indicates that no bearer token was provided ErrNoToken = errors.New("api: no token provided") // ErrInvalidParameters indicates that parameters used in an API call are not valid ErrInvalidParameters = errors.New("api: invalid parameters") // ErrValidationFailed indicates that a resource validation failed ErrValidationFailed = errors.New("api: validation failed") // ErrNoSuchProduction indicates that the production does not exist ErrNoSuchProduction = errors.New("api: production doesn't exist") // ErrNoSuchResource indicates that the resource does not exist ErrNoSuchResource = errors.New("api: resource doesn't exist") // ErrNoSuchAsset indicates that the asset does not exist ErrNoSuchAsset = errors.New("api: asset doesn't exist") // ErrBuildFailed indicates that the feed build failed ErrBuildFailed = errors.New("api: build failed") // ErrInternalError indicates that an unspecified internal error happened ErrInternalError = errors.New("api: internal error") )
Functions ¶
func DefaultEpisodeMetadata ¶
DefaultEpisodeMetadata creates a default set of labels etc for a Episode resource
guid: <unique id> 'item.guid' date: <publish date> REQUIRED 'item.pubDate' season: <season number> OPTIONAL 'item.itunes.season' episode: <episode number> REQUIRED 'item.itunes.episode' explicit: True | False REQUIRED 'channel.itunes.explicit' type: Full | Trailer | Bonus REQUIRED 'item.itunes.episodeType' block: Yes OPTIONAL 'item.itunes.block' Anything else than 'Yes' has no effect
func DefaultShowMetadata ¶
DefaultShowMetadata creates a default set of labels etc for a Show resource
language: <ISO639 two-letter-code> REQUIRED 'channel.language' explicit: True | False REQUIRED 'channel.itunes.explicit' type: Episodic | Serial REQUIRED 'channel. itunes.type' block: Yes OPTIONAL 'channel.itunes.block' Anything else than 'Yes' has no effect complete: Yes OPTIONAL 'channel.itunes.complete' Anything else than 'Yes' has no effect
func ErrorResponse ¶ added in v0.9.6
ErrorResponse responds with an ErrorObject
func LoadResource ¶
LoadResource takes a byte array and determines its kind before unmarshalling it into its struct form
func StandardResponse ¶ added in v0.9.6
StandardResponse is the default way to respond to API requests
func ValidResourceName ¶ added in v0.9.4
ValidResourceName verifies that a name is valid for a resource. The following rules apply:
'name' must contain only lowercase letters, numbers, dashes (-), underscores (_). 'name' must contain 8-64 characters. Spaces and dots (.) are not allowed.
Types ¶
type Assertion ¶
type Assertion struct {
Type int // 0 == warning, 1 == error
Txt string // description of the problem
Err error
}
Assertion is used to collect validation information
type Asset ¶
type Asset struct {
URI string `json:"uri" yaml:"uri" binding:"required"` // REQUIRED
Title string `json:"title,omitempty" yaml:"title,omitempty"` // OPTIONAL
Anchor string `json:"anchor,omitempty" yaml:"anchor,omitempty"` // OPTIONAL
Rel string `json:"rel,omitempty" yaml:"rel,omitempty"` // OPTIONAL
Type string `json:"type,omitempty" yaml:"type,omitempty"` // OPTIONAL
Size int `json:"size,omitempty" yaml:"size,omitempty"` // OPTIONAL
}
Asset provides a link to a media resource
func (*Asset) FingerprintURI ¶
FingerprintURI is used in rewriting the URI when Rel == IMPORT
func (*Asset) ResolveURI ¶
ResolveURI re-writes the URI
func (*Asset) Validate ¶
Validate verifies the integrity of struct Resource
URI string `json:"uri" yaml:"uri" binding:"required"` // REQUIRED Title string `json:"title,omitempty" yaml:"title,omitempty"` // OPTIONAL Anchor string `json:"anchor,omitempty" yaml:"anchor,omitempty"` // OPTIONAL Rel string `json:"rel,omitempty" yaml:"rel,omitempty"` // OPTIONAL Type string `json:"type,omitempty" yaml:"type,omitempty"` // OPTIONAL Size int `json:"size,omitempty" yaml:"size,omitempty"` // OPTIONAL
type AuthorizationRequest ¶
type AuthorizationRequest struct {
Secret string `json:"secret" binding:"required"`
Realm string `json:"realm" binding:"required"`
ClientID string `json:"client_id" binding:"required"`
ClientType string `json:"client_type" binding:"required"` // user,app,bot
UserID string `json:"user_id" binding:"required"`
Scope string `json:"scope" binding:"required"`
Duration int64 `json:"duration" binding:"required"`
}
AuthorizationRequest struct is used to request a token Imported from https://github.com/txsvc/service/blob/main/pkg/auth/types.go
type AuthorizationResponse ¶
type AuthorizationResponse struct {
Realm string `json:"realm" binding:"required"`
ClientID string `json:"client_id" binding:"required"`
Token string `json:"token" binding:"required"`
}
AuthorizationResponse provides a valid token Imported from https://github.com/txsvc/service/blob/main/pkg/auth/types.go
type Build ¶ added in v0.9.4
type Build struct {
GUID string `json:"guid" binding:"required"`
FeedURL string `json:"feed"`
FeedAliasURL string `json:"alias"`
}
Build initiates the build of the feed
type Category ¶
type Category struct {
Name string `json:"name" yaml:"name" binding:"required"` // REQUIRED
SubCategory []string `json:"subcategory" yaml:"subcategory,omitempty"` // OPTIONAL
}
Category is the show/episodes category and it's subcategories
type Episode ¶
type Episode struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion" binding:"required"` // REQUIRED default: v1.0
Kind string `json:"kind" yaml:"kind" binding:"required"` // REQUIRED default: episode
Metadata Metadata `json:"metadata" yaml:"metadata" binding:"required"` // REQUIRED
Description EpisodeDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED
Image Asset `json:"image" yaml:"image" binding:"required"` // REQUIRED 'item.itunes.image'
Enclosure Asset `json:"enclosure" yaml:"enclosure" binding:"required"` // REQUIRED
}
Episode holds all metadata related to a podcast episode
func DefaultEpisode ¶
DefaultEpisode creates a default episode struc
func (*Episode) ParentGUID ¶
ParentGUID is a convenience method to access the resources parent guid
func (*Episode) PublishDate ¶
PublishDate is a convenience method to access the pub date
func (*Episode) PublishDateTimestamp ¶
PublishDateTimestamp converts a RFC1123Z formatted timestamp into UNIX timestamp
func (*Episode) Validate ¶
Validate verifies the integrity of struct Episode
APIVersion string `json:"apiVersion" yaml:"apiVersion" binding:"required"` // REQUIRED default: v1.0 Kind string `json:"kind" yaml:"kind" binding:"required"` // REQUIRED default: episode Metadata Metadata `json:"metadata" yaml:"metadata" binding:"required"` // REQUIRED Description EpisodeDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED Image Resource `json:"image" yaml:"image" binding:"required"` // REQUIRED 'item.itunes.image' Enclosure Resource `json:"enclosure" yaml:"enclosure" binding:"required"` // REQUIRED
type EpisodeDescription ¶
type EpisodeDescription struct {
Title string `json:"title" yaml:"title" binding:"required"` // REQUIRED 'item.title' 'item.itunes.title'
Summary string `json:"summary" yaml:"summary" binding:"required"` // REQUIRED 'item.description'
EpisodeText string `json:"episodeText,omitempty" yaml:"episodeText,omitempty" binding:"required"` // REQUIRED 'item.itunes.summary'
Link Asset `json:"link" yaml:"link"` // RECOMMENDED 'item.link'
Duration int `json:"duration" yaml:"duration" binding:"required"` // REQUIRED 'item.itunes.duration'
}
EpisodeDescription holds essential episode metadata
func (*EpisodeDescription) Validate ¶
func (d *EpisodeDescription) Validate(v *Validator) *Validator
Validate verifies the integrity of struct EpisodeDescription
Title string `json:"title" yaml:"title" binding:"required"` // REQUIRED 'item.title' 'item.itunes.title' Summary string `json:"summary" yaml:"summary" binding:"required"` // REQUIRED 'item.description' EpisodeText string `json:"episodeText,omitempty" yaml:"episodeText,omitempty" binding:"required"` // REQUIRED 'item.itunes.summary' Link Resource `json:"link" yaml:"link"` // RECOMMENDED 'item.link' Duration int `json:"duration" yaml:"duration" binding:"required"` // REQUIRED 'item.itunes.duration'
type Import ¶ added in v0.9.4
type Import struct {
Source string `json:"src" binding:"required"`
Dest string `json:"dest" binding:"required"`
}
Import is used by the import task
type Metadata ¶
type Metadata struct {
Name string `json:"name" yaml:"name" binding:"required"` // REQUIRED <unique name>
Labels map[string]string `json:"labels" yaml:"labels,omitempty"` // REQUIRED
}
Metadata contains information describing a resource
type Owner ¶
type Owner struct {
Name string `json:"name" yaml:"name" binding:"required"` // REQUIRED
Email string `json:"email" yaml:"email" binding:"required"` // REQUIRED
}
Owner describes the owner of the show/podcast
type Production ¶
type Production struct {
Name string `json:"name" binding:"required"`
GUID string `json:"guid,omitempty"`
Owner string `json:"owner"`
Title string `json:"title"`
Summary string `json:"summary"`
BuildDate int64 `json:"build_date"`
// internal
Created int64 `json:"-"`
Updated int64 `json:"-"`
}
Production is the parent struct of all other resources.
type ProductionList ¶
type ProductionList struct {
Productions []*Production `json:"productions" `
}
ProductionList returns a list of productions
type Resource ¶
type Resource struct {
Name string `json:"name"`
GUID string `json:"guid"`
Kind string `json:"kind"`
ParentGUID string `json:"parent_guid"`
Location string `json:"location"` // path to the .yaml
// only used in assets e.g. .mp3/.png
ContentType string `json:"content_type"`
Size int64 `json:"size"`
// internal
Created int64 `json:"-"`
Updated int64 `json:"-"`
}
Resource is used to maintain a repository of all existing resources across all shows
type ResourceList ¶
type ResourceList struct {
Resources []*Resource `json:"resources" `
}
ResourceList returns a list of resources
type ResourceLoaderFunc ¶
ResourceLoaderFunc implements loading of resources
type ResourceMetadata ¶
type ResourceMetadata struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion" binding:"required"` // REQUIRED default: v1.0
Kind string `json:"kind" yaml:"kind" binding:"required"` // REQUIRED default: show
Metadata Metadata `json:"metadata" yaml:"metadata" binding:"required"` // REQUIRED
}
ResourceMetadata holds only the kind and metadata of a resource
func LoadResourceMetadata ¶
func LoadResourceMetadata(data []byte) (*ResourceMetadata, error)
LoadResourceMetadata reads only the metadata of a resource
func (*ResourceMetadata) GUID ¶
func (r *ResourceMetadata) GUID() string
GUID is a convenience method to access the resources guid
type Show ¶
type Show struct {
APIVersion string `json:"apiVersion" yaml:"apiVersion" binding:"required"` // REQUIRED default: v1.0
Kind string `json:"kind" yaml:"kind" binding:"required"` // REQUIRED default: show
Metadata Metadata `json:"metadata" yaml:"metadata" binding:"required"` // REQUIRED
Description ShowDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED
Image Asset `json:"image" yaml:"image" binding:"required"` // REQUIRED 'channel.itunes.image'
}
Show holds all metadata related to a podcast/show
func DefaultShow ¶
DefaultShow creates a default show struc
func (*Show) Validate ¶
Validate verifies the integrity of struct Show
APIVersion string `json:"apiVersion" yaml:"apiVersion" binding:"required"` // REQUIRED default: v1.0 Kind string `json:"kind" yaml:"kind" binding:"required"` // REQUIRED default: show Metadata Metadata `json:"metadata" yaml:"metadata" binding:"required"` // REQUIRED Description ShowDescription `json:"description" yaml:"description" binding:"required"` // REQUIRED Image Resource `json:"image" yaml:"image" binding:"required"` // REQUIRED 'channel.itunes.image'
type ShowDescription ¶
type ShowDescription struct {
Title string `json:"title" yaml:"title" binding:"required"` // REQUIRED 'channel.title' 'channel.itunes.title'
Summary string `json:"summary" yaml:"summary" binding:"required"` // REQUIRED 'channel.description'
Link Asset `json:"link" yaml:"link"` // RECOMMENDED 'channel.link'
Category Category `json:"category" yaml:"category" binding:"required"` // REQUIRED channel.category
Owner Owner `json:"owner" yaml:"owner"` // RECOMMENDED 'channel.itunes.owner'
Author string `json:"author" yaml:"author"` // RECOMMENDED 'channel.itunes.author'
Copyright string `json:"copyright,omitempty" yaml:"copyright,omitempty"` // OPTIONAL 'channel.copyright'
NewFeed *Asset `json:"newFeed,omitempty" yaml:"newFeed,omitempty"` // OPTIONAL channel.itunes.new-feed-url -> move to label
}
ShowDescription holds essential show metadata
func (*ShowDescription) Validate ¶
func (d *ShowDescription) Validate(v *Validator) *Validator
Validate verifies the integrity of struct ShowDescription
Title string `json:"title" yaml:"title" binding:"required"` // REQUIRED 'channel.title' 'channel.itunes.title' Summary string `json:"summary" yaml:"summary" binding:"required"` // REQUIRED 'channel.description' Link Resource `json:"link" yaml:"link"` // RECOMMENDED 'channel.link' Category Category `json:"category" yaml:"category" binding:"required"` // REQUIRED channel.category Owner Owner `json:"owner" yaml:"owner"` // RECOMMENDED 'channel.itunes.owner' Author string `json:"author" yaml:"author"` // RECOMMENDED 'channel.itunes.author' Copyright string `json:"copyright,omitempty" yaml:"copyright,omitempty"` // OPTIONAL 'channel.copyright' NewFeed *Resource `json:"newFeed,omitempty" yaml:"newFeed,omitempty"` // OPTIONAL channel.itunes.new-feed-url -> move to label
type StatusObject ¶
type StatusObject struct {
Status int `json:"status" binding:"required"`
Message string `json:"message" binding:"required"`
RootError error `json:"-"`
}
StatusObject is used to report operation status and errors in an API request. The struct can be used as a response object or be treated as an error object
func NewErrorStatus ¶ added in v0.9.4
func NewErrorStatus(s int, e error) StatusObject
NewErrorStatus initializes a new StatusObject from an error
func NewStatus ¶ added in v0.9.4
func NewStatus(s int, m string) StatusObject
NewStatus initializes a new StatusObject
func (*StatusObject) Error ¶
func (so *StatusObject) Error() string
type Validatable ¶
Validatable is the interface that maust be implemented to support recursive validations of strucs
type Validator ¶
Validator collects assertions
func NewValidator ¶
NewValidator initializes and returns a new Validator
func (*Validator) AssertContains ¶
AssertContains verifies that a map contains key
func (*Validator) AssertError ¶
AssertError add an error assertion
func (*Validator) AssertExistsError ¶
AssertExistsError verifies that a struct exists
func (*Validator) AssertISO639 ¶
AssertISO639 verifies that src complies with ISO 639-1
func (*Validator) AssertNotEmpty ¶
AssertNotEmpty verifies that a map is not empty
func (*Validator) AssertNotNil ¶
AssertNotNil verifies that an attribute is not nil
func (*Validator) AssertNotZero ¶
AssertNotZero verifies that a map is not empty
func (*Validator) AssertStringError ¶
AssertStringError verifies a string
func (*Validator) AssertStringExists ¶
AssertStringExists verifies a string is not empty
func (*Validator) AssertWarning ¶
AssertWarning add an warning assertion
func (*Validator) Validate ¶
func (v *Validator) Validate(src Validatable) *Validator
Validate starts the chain of validations