diva

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 5 Imported by: 0

README

diva

Build Status GoDoc License MIT

Convert diva.cmore.se URLs into img-cdn-cmore.b17g.services URLs

Installation

go get -u github.com/TV4/diva

Usage

Basic
package main

import (
	"fmt"

	"github.com/TV4/diva"
)

func main() {
	rawurl := "http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1"

	fmt.Println(diva.CDNRawURL(rawurl))
}
Custom base URL
package main

import (
	"fmt"

	"github.com/TV4/diva"
)

func main() {
	rawurl := "http://diva.cmore.se/image.aspx?formatid=221&id=a21630f5-ef51-4632-bf6f-cc94073d3cb1"

	dc := diva.NewConverter("https://example.com/")

	fmt.Println(dc.CDNRawURL(rawurl))
}

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

func CDNRawURL(rawurl string) string

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

func NewURL(id, id2, formatID string) (*url.URL, error)

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

func Parse(rawurl string) (*url.URL, error)

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

func NewConverter(baseurl string) *Converter

NewConverter returns a new converter instance.

func (*Converter) CDNRawURL added in v0.2.0

func (c *Converter) CDNRawURL(rawurl string) string

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

func (c *Converter) NewURL(id, id2, formatID string) (*url.URL, error)

NewURL creates a new image URL with the given ids and format

func (*Converter) Parse added in v0.2.0

func (c *Converter) Parse(rawurl string) (*url.URL, error)

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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL