Documentation ¶
Overview ¶
Package diva converts diva.cmore.se URLs into img-cdn-cmore.b17g.services URLs
Installation ¶
Just go get the package:
go get -u github.com/TV4/diva
Usage ¶
A small usage example
package main import ( "fmt" "github.com/TV4/diva" ) func main() { fmt.Println(diva.CDNRawURL("http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1")) }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrMissingBaseURL is returned when trying to generate an URL without having // configured a base URL. ErrMissingBaseURL = fmt.Errorf("missing base URL") // ErrNotDivaURL is returned when trying to parse a // rawurl that isn’t from diva.cmore.se ErrNotDivaURL = fmt.Errorf("not a diva URL") // ErrMissingRequiredArgument is returned if the id // or formatid query parameters are missing ErrMissingRequiredArgument = fmt.Errorf("missing required argument") )
Functions ¶
func CDNRawURL ¶
CDNRawURL converts diva rawurl string into CDN rawurl string
Example ¶
package main import ( "fmt" "github.com/TV4/diva" ) func main() { fmt.Println(diva.CDNRawURL("http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1")) }
Output: https://img-cdn-cmore.b17g.services/a21630f5-ef51-4632-bf6f-cc94073d3cb1/221.img
func NewURL ¶
NewURL creates a new image URL with the given ids and format
Example ¶
package main import ( "fmt" "github.com/TV4/diva" ) func main() { if u, err := diva.NewURL("id1", "id2", "format"); err == nil { fmt.Println(u.String()) } }
Output: https://img-cdn-cmore.b17g.services/id1/id2/format.img
func Parse ¶
Parse diva rawurl into CDN *url.URL
Example ¶
package main import ( "fmt" "github.com/TV4/diva" ) func main() { if u, err := diva.Parse("http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1"); err == nil { fmt.Println(u.String()) } }
Output: https://img-cdn-cmore.b17g.services/a21630f5-ef51-4632-bf6f-cc94073d3cb1/221.img
Types ¶
type Converter ¶ added in v0.2.0
type Converter struct {
// contains filtered or unexported fields
}
Converter converts diva URLs into CDN URLs.
func NewConverter ¶ added in v0.2.0
NewConverter returns a new converter instance.
func (*Converter) CDNRawURL ¶ added in v0.2.0
CDNRawURL converts diva rawurl string into CDN rawurl string
Example ¶
conv := NewConverter("https://example.com/") fmt.Println(conv.CDNRawURL("http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1"))
Output: https://example.com/a21630f5-ef51-4632-bf6f-cc94073d3cb1/221.img
func (*Converter) NewURL ¶ added in v0.2.0
NewURL creates a new image URL with the given ids and format
func (*Converter) Parse ¶ added in v0.2.0
Parse diva rawurl into CDN *url.URL
Example ¶
conv := NewConverter("https://example.com/") if u, err := conv.Parse("http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1"); err == nil { fmt.Println(u.String()) }
Output: https://example.com/a21630f5-ef51-4632-bf6f-cc94073d3cb1/221.img
func (*Converter) UseComet6URLParsing ¶ added in v0.2.1
func (c *Converter) UseComet6URLParsing()
Click to show internal directories.
Click to hide internal directories.