source

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package output holds the supported sources.

Example (Local)
package main

import (
	"fmt"
	"os"
	"path/filepath"
	"reflect"

	"github.com/victorpopkov/go-appcast/source"
)

func testdataPath(paths ...string) string {
	testdataPath := "./testdata/"

	pwd, err := os.Getwd()
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	return filepath.Join(pwd, testdataPath, filepath.Join(paths...))
}

func main() {
	src := source.NewLocal(testdataPath("example.xml"))

	err := src.Load()
	if err != nil {
		panic(err)
	}

	fmt.Println("Type:", reflect.TypeOf(src))
	fmt.Println("Content:", fmt.Sprintf("%d (%s)", len(src.Content()), "length"))
	fmt.Println("Checksum:", fmt.Sprintf("%s (%s)", src.Checksum().String(), src.Checksum().Algorithm()))

}
Output:

Type: *source.Local
Content: 2048 (length)
Checksum: 0cb017e2dfd65e07b54580ca8d4eedbfcf6cef5824bcd9539a64afb72fa9ce8c (SHA256)
Example (Remote)
// mock the request
content := testdata("example.xml")
httpmock.ActivateNonDefault(source.DefaultClient.HTTPClient)
httpmock.RegisterResponder("GET", "https://www.adium.im/sparkle/appcast-release.xml", httpmock.NewBytesResponder(200, content))
defer httpmock.DeactivateAndReset()

// example
src, err := source.NewRemote("https://www.adium.im/sparkle/appcast-release.xml")
if err != nil {
	panic(err)
}

err = src.Load()
if err != nil {
	panic(err)
}

fmt.Println("Type:", reflect.TypeOf(src))
fmt.Println("Content:", fmt.Sprintf("%d (%s)", len(src.Content()), "length"))
fmt.Println("Checksum:", fmt.Sprintf("%s (%s)", src.Checksum().String(), src.Checksum().Algorithm()))
Output:

Type: *source.Remote
Content: 2048 (length)
Checksum: 0cb017e2dfd65e07b54580ca8d4eedbfcf6cef5824bcd9539a64afb72fa9ce8c (SHA256)

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultClient = client.New()

DefaultClient is the default Client that is used for making requests in the appcast package.

View Source
var LocalReadFile = ioutil.ReadFile

Functions

This section is empty.

Types

type Local

type Local struct {
	*appcaster.Source
	// contains filtered or unexported fields
}

Local represents an appcast source from the local file.

func NewLocal

func NewLocal(path string) *Local

NewLocal returns a new Local instance pointer with the Local.filepath set.

func (*Local) Filepath

func (l *Local) Filepath() string

Filepath is a Local.filepath getter.

func (*Local) Load

func (l *Local) Load() error

Load loads an appcast content into the Local.Source.content from the local file by using the path specified in Local.filepath set earlier.

func (*Local) SetFilepath

func (l *Local) SetFilepath(filepath string)

SetFilepath is a Local.filepath setter.

type Localer

type Localer interface {
	appcaster.Sourcer
	Filepath() string
	SetFilepath(filepath string)
}

Localer is the interface that wraps the Local methods.

type Remote

type Remote struct {
	*appcaster.Source
	// contains filtered or unexported fields
}

Remote represents an appcast source from the remote location.

func NewRemote

func NewRemote(src interface{}) (*Remote, error)

NewRemote returns a new Remote instance pointer with the prepared Remote.request and Remote.url ready to be used Remote.load.

Supports both the remote URL string or Request struct pointer as an argument.

func (*Remote) Load

func (r *Remote) Load() error

Load loads an appcast content into the Remote.Source.content from the remote source by using the Remote.request set earlier.

func (*Remote) Request

func (r *Remote) Request() *client.Request

Request is a Remote.request getter.

func (*Remote) SetRequest

func (r *Remote) SetRequest(request *client.Request)

SetRequest is a Remote.request setter.

func (*Remote) SetUrl

func (r *Remote) SetUrl(url string)

SetUrl is a Remote.url setter.

func (*Remote) Url

func (r *Remote) Url() string

Url is a Remote.url getter.

type Remoter

type Remoter interface {
	appcaster.Sourcer
	Request() *client.Request
	SetRequest(request *client.Request)
	Url() string
	SetUrl(url string)
}

Remoter is the interface that wraps the Remote methods.

Jump to

Keyboard shortcuts

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