resource

package
Version: v0.0.0-...-5a98790 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package resource helps managing arguments and files for a conversion.

All functions return our standard xerror.Error in case of error.

Index

Constants

View Source
const (
	// RemoteURLCustomHTTPHeaderCanonicalBaseKey is the base key
	// of custom headers send to the remote URL.
	RemoteURLCustomHTTPHeaderCanonicalBaseKey string = "Gotenberg-Remoteurl-"
	// WebhookURLCustomHTTPHeaderCanonicalBaseKey is the base key
	// of custom headers send to the webhook URL.
	WebhookURLCustomHTTPHeaderCanonicalBaseKey string = "Gotenberg-Webhookurl-"
)
View Source
const TemporaryDirectory string = "tmp"

TemporaryDirectory is the directory where all the resources directory are located.

Variables

This section is empty.

Functions

func GoogleChromeRpccBufferSizeArg

func GoogleChromeRpccBufferSizeArg(r Resource, config conf.Config) (int64, error)

GoogleChromeRpccBufferSizeArg is a helper for retrieving the "googleChromeRpccBufferSize" argument as int64.

It also validates it against the application configuration.

func HeaderFooterContents

func HeaderFooterContents(r Resource, config conf.Config) (string, string, error)

HeaderFooterContents is a helper for retrieving the content of the files "header.html" and "footer.html".

func MarginArgs

func MarginArgs(r Resource, config conf.Config) (float64, float64, float64, float64, error)

MarginArgs is a helper for retrieving the "marginTop", "marginBottom", "marginLeft" and "marginRight" arguments as float64.

func PaperSizeArgs

func PaperSizeArgs(r Resource, config conf.Config) (float64, float64, error)

PaperSizeArgs is a helper for retrieving the "paperWidth" and "paperHeight" arguments as float64.

func RemoteURLCustomHTTPHeaders

func RemoteURLCustomHTTPHeaders(r Resource) map[string]string

RemoteURLCustomHTTPHeaders is a helper for retrieving the custom headers for the URL conversion.

func ScaleArg

func ScaleArg(r Resource, config conf.Config) (float64, error)

ScaleArg is a helper for retrieving the "scale" argument as float64.

func WaitDelayArg

func WaitDelayArg(r Resource, config conf.Config) (float64, error)

WaitDelayArg is a helper for retrieving the "waitDelay" argument as float64.

It also validates it against the application configuration.

func WaitTimeoutArg

func WaitTimeoutArg(r Resource, config conf.Config) (float64, error)

WaitTimeoutArg is a helper for retrieving the "waitTimeout" argument as float64.

It also validates it against the application configuration.

func WebhookURLCustomHTTPHeaders

func WebhookURLCustomHTTPHeaders(r Resource) map[string]string

WebhookURLCustomHTTPHeaders is a helper for retrieving the custom headers for the webhook URL.

func WebhookURLTimeoutArg

func WebhookURLTimeoutArg(r Resource, config conf.Config) (float64, error)

WebhookURLTimeoutArg is a helper for retrieving the "webhookURLTimeout" argument as float64.

It also validates it against the application configuration.

Types

type ArgKey

type ArgKey string

ArgKey is a type for arguments' keys.

const (
	// ResultFilenameArgKey is the key
	// of the argument "resultFilename".
	ResultFilenameArgKey ArgKey = "resultFilename"
	// WaitTimeoutArgKey is the key
	// of the argument "waitTimeout".
	WaitTimeoutArgKey ArgKey = "waitTimeout"
	// WebhookURLArgKey is the key
	// of the argument "webhookURL".
	WebhookURLArgKey ArgKey = "webhookURL"
	// WebhookURLTimeoutArgKey is the key
	// of the argument "webhookURLTimeout".
	WebhookURLTimeoutArgKey ArgKey = "webhookURLTimeout"
	// RemoteURLArgKey is the key
	// of the argument "remoteURL".
	RemoteURLArgKey ArgKey = "remoteURL"
	// WaitDelayArgKey is the key
	// of the argument "waitDelay".
	WaitDelayArgKey ArgKey = "waitDelay"
	// PaperWidthArgKey is the key
	// of the argument "paperWidth".
	PaperWidthArgKey ArgKey = "paperWidth"
	// PaperHeightArgKey is the key
	// of the argument "paperHeight".
	PaperHeightArgKey ArgKey = "paperHeight"
	// MarginTopArgKey is the key
	// of the argument "marginTop".
	MarginTopArgKey ArgKey = "marginTop"
	// MarginBottomArgKey is the key
	// of the argument "marginBottom".
	MarginBottomArgKey ArgKey = "marginBottom"
	// MarginLeftArgKey is the key
	// of the argument "marginLeft".
	MarginLeftArgKey ArgKey = "marginLeft"
	// MarginRightArgKey is the key
	// of the argument "marginRight".
	MarginRightArgKey ArgKey = "marginRight"
	// LandscapeArgKey is the key
	// of the argument "landscape".
	LandscapeArgKey ArgKey = "landscape"
	// PageRangesArgKey is the key
	// of the argument "pageRanges".
	PageRangesArgKey ArgKey = "pageRanges"
	// GoogleChromeRpccBufferSizeArgKey is the key
	// of the argument "googleChromeRpccBufferSize".
	GoogleChromeRpccBufferSizeArgKey ArgKey = "googleChromeRpccBufferSize"
	// ScaleArgKey is the key
	// of the argument "scale".
	ScaleArgKey ArgKey = "scale"
)

func ArgKeys

func ArgKeys() []ArgKey

ArgKeys returns a slice containing all available arguments' keys.

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

Resource helps managing arguments and files for a conversion.

func New

func New(logger xlog.Logger, directoryName string) (Resource, error)

New creates a Resource where its files will be located in the given directory name.

func (Resource) BoolArg

func (r Resource) BoolArg(key ArgKey, defaultValue bool) (bool, error)

BoolArg returns the boolean representation of the argument identified by given key.

It works in the same manner as xassert.Bool.

func (Resource) Close

func (r Resource) Close() error

Close removes the working directory of the Resource if it exists.

func (Resource) DirPath

func (r Resource) DirPath() string

DirPath returns the directory path of the Resource.

func (Resource) Fcontent

func (r Resource) Fcontent(filename, defaultValue string) (string, error)

Fcontent returns the string content of the given filename.

If filename does not exist within the Resource, returns the default value.

func (Resource) Float64Arg

func (r Resource) Float64Arg(key ArgKey, defaultValue float64, rules ...xassert.RuleFloat64) (float64, error)

Float64Arg returns the float64 representation of the argument identified by given key.

It works in the same manner as xassert.Float64.

func (Resource) Fpath

func (r Resource) Fpath(filename string) (string, error)

Fpath returns the path of the given filename. This filename should exist whithin the Resource.

func (Resource) Fpaths

func (r Resource) Fpaths(exts ...string) ([]string, error)

Fpaths returns the paths of the files having one of the given file extensions.

It should found at least one path.

func (Resource) HasArg

func (r Resource) HasArg(key ArgKey) bool

HasArg returns true if given key exists among the Resource and its value is not empty.

func (Resource) Int64Arg

func (r Resource) Int64Arg(key ArgKey, defaultValue int64, rules ...xassert.RuleInt64) (int64, error)

Int64Arg returns the int64 representation of the argument identified by given key.

It works in the same manner as xassert.Int64.

func (Resource) StringArg

func (r Resource) StringArg(key ArgKey, defaultValue string, rules ...xassert.RuleString) (string, error)

StringArg returns the value of the argument identified by given key.

It works in the same manner as xassert.String.

func (*Resource) WithArg

func (r *Resource) WithArg(key ArgKey, value string)

WithArg add a new argument to the Resource.

func (*Resource) WithCustomHTTPHeader

func (r *Resource) WithCustomHTTPHeader(key string, value string)

WithCustomHTTPHeader add a new custom header to the Resource. Given key should be in canonical format.

func (*Resource) WithFile

func (r *Resource) WithFile(filename string, in io.Reader) error

WithFile add a new file to the Resource.

Jump to

Keyboard shortcuts

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