v2.14.0+incompatible Latest Latest

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 16 Imported by: 0




This section is empty.


View Source
var (
	ErrConversionTimeout = errors.New("conversion timed out")


func InitWorkers

func InitWorkers(maxWorkers, maxQueue, t int) chan<- Work


type AWSS3

type AWSS3 struct {
	Region       string
	AccessKey    string
	AccessSecret string
	S3Bucket     string
	S3Key        string
	S3Acl        string

type Conversion

type Conversion struct{}

Conversion represents the most basic, skeleton conversion job. Currently, it is assumed that the input is a HTML (or similar) resource, and the output is a PDF. Conversion implements the Converter interface with dummy methods. Any child conversion type should overwrite these methods.

func (Conversion) Convert

func (c Conversion) Convert(s ConversionSource, done <-chan struct{}) ([]byte, error)

Convert should return a byte slice containing the converted resource, synchronously. It should terminate any long-running processes (and Goroutines) if the done channel is returned.

func (Conversion) Upload

func (c Conversion) Upload(b []byte) (bool, error)

Upload should take a byte slice, and return a boolean indicating if the data was used for post-processing, e.g. uploading to a remote host like S3. It should always return false if there is an error.

type ConversionSource

type ConversionSource struct {
	// URI represents the actual path to a remote (web) or local resource
	// to be converted.
	URI string
	// OriginalURI may contain the original path to a remote resource to be
	// converted if it is downloaded for local conversion.
	// This normally happens when the resource is an `octet-stream`.
	// It is only metadata, and it should NOT be used as the conversion source.
	OriginalURI string
	// Mime represents the content type of the source. It will be set to
	// `application/octet-stream` if it is unable to determine the type.
	// For more information see:
	Mime string
	// IsLocal should be true if the URI relies on a local conversion strategy,
	// and false if the target is a remote source (that does not require
	// pre-processing).
	IsLocal bool

ConversionSource contains the target resource path, and its MIME type. It may contain additional metadata about the conversion source.

func NewConversionSource

func NewConversionSource(uri string, body io.Reader, ext string) (*ConversionSource, error)

NewConversionSource creates, and returns a new ConversionSource. It accepts either a URI to a remote resource or a reader containing a stream of bytes. If both parameters are specified, the reader takes precedence. The ConversionSource is prepared using one of two strategies: a local conversion (see rawSource) or a remote conversion (see uriSource).

func (ConversionSource) GetActualURI

func (s ConversionSource) GetActualURI() string

GetActualURI returns the original conversion target. The URI field may not contain the original conversion target as it may be overwritten when using a local conversion strategy.

type Converter

type Converter interface {
	Convert(ConversionSource, <-chan struct{}) ([]byte, error)
	Upload([]byte) (bool, error)

type UploadConversion

type UploadConversion struct {

func (UploadConversion) Upload

func (c UploadConversion) Upload(b []byte) (bool, error)

type Work

type Work struct {
	// contains filtered or unexported fields

func NewWork

func NewWork(wq chan<- Work, c Converter, s ConversionSource) Work

func (Work) Cancel

func (w Work) Cancel()

Cancel will close the done channel. This will indicate to child Goroutines that the job has been terminated, and the results are no longer needed.

func (Work) Cancelled

func (w Work) Cancelled() <-chan struct{}

Cancelled returns a channel that will indicate when a job has been completed.

func (Work) Error

func (w Work) Error() <-chan error

Error returns a channel that will be used for publishing errors from a conversion.

func (Work) Process

func (w Work) Process(t int)

func (Work) Success

func (w Work) Success() <-chan []byte

Success returns a channel that will be used for publishing the output of a conversion.

func (Work) Uploaded

func (w Work) Uploaded() <-chan struct{}

Uploaded returns a channel that will be closed when a conversion has been uploaded.

type Worker

type Worker struct {
	// contains filtered or unexported fields


Path Synopsis

Jump to

Keyboard shortcuts

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