var ( // ErrNotFound is the error returned when the server responses with the http.StatusNotFound. ErrNotFound = errors.New("not found") // ErrBadRequest is an error returned when the client input was not valid. ErrBadRequest = errors.New("bad request") // ErrNotImplemented is the error that states that some functionality is not implemented yet. ErrNotImplemented = errors.New("not implemented") // ErrInternalError is an internal server error. ErrInternalError = errors.New("internal server error") // ErrBadGateway is an error that states for the bad gateway HTTP error. ErrBadGateway = errors.New("bad gateway") // ErrUnauthorized is an error that states invalid authrization of given request. = errors.New("unauthorized") // ErrTimedOut is an error that states the request had timed out. ErrTimedOut = errors.New("request timed out") )
var ( // ErrMissingData is an error returned when the provided input has no data. ErrMissingData = errors.New("missing input data") // ErrContentType is an error returned when provided content type is not defined or invalid. ErrContentType = errors.New("invalid content type") // ErrContentTypeDeclared is an error returned when the query. ErrContentTypeDeclared = errors.New("content type is already declared") )
BySelector is a structure that defines a selector with it's query 'by' type.
type BySelector struct { Selector string `json:"selector"` By selector.ByType `json:"by"` }
func (b BySelector) Validate() error
Validate checks validity of the selector.
Client is a structure that is a HTTP client for the unihtml server.
type Client struct { Options Options Client *http.Client }
func New(o Options) *Client
New creates new client with provided options.
func (c *Client) ConvertHTML(ctx context.Context, q *Query) (*PDFResponse, error)
ConvertHTML converts provided Query input into PDF file data. Implements creator.HTMLConverter interface.
func (c *Client) HealthCheck(ctx context.Context) error
HealthCheck connects to the server and check the health status of the server.
Option is a function that changes client options.
type Option func(o *Options)
func WithDefaultTimeout(option time.Duration) Option
WithDefaultTimeout sets the DefaultTimeout option for the client options.
func WithHTTPS(useHTTPS bool) Option
WithHTTPS sets the TLS option for the client options.
func WithHostname(option string) Option
WithHostname sets the Hostname option for the client options.
func WithPort(option int) Option
WithPort sets the Port option for the client options.
func WithPrefix(prefix string) Option
WithPrefix sets the client prefix.
Options are the client options used by the HTTP client.
type Options struct { HTTPS bool Hostname string Port int DefaultTimeout time.Duration Prefix string }
func ParseOptions(connectPath string) (Options, error)
ParseOptions parses options for the Client.
func (o *Options) Addr() string
Addr gets the HTTP address URI used by the http.Client.
PDFResponse is the response used by the HTMLConverter.
type PDFResponse struct { ID string `json:"id"` Data []byte `json:"data"` }
PageParameters are the query parameters used in the PDF generation.
type PageParameters struct { // PaperWidth sets the width of the paper. PaperWidth sizes.Length `schema:"paper-width" json:"paperWidth"` // PaperHeight is the height of the output paper. PaperHeight sizes.Length `schema:"paper-height" json:"paperHeight"` // PageSize is the page size string. PageSize *sizes.PageSize `schema:"page-size" json:"pageSize"` // Orientation defines if the output should be in a landscape format. Orientation sizes.Orientation `schema:"orientation" json:"orientation"` // MarginTop sets up the Top Margin for the output. MarginTop sizes.Length `schema:"margin-top" json:"marginTop"` // MarginBottom sets up the Bottom Margin for the output. MarginBottom sizes.Length `schema:"margin-bottom" json:"marginBottom"` // MarginLeft sets up the Left Margin for the output. MarginLeft sizes.Length `schema:"margin-left" json:"marginLeft"` // MarginRight sets up the Right Margin for the output. MarginRight sizes.Length `schema:"margin-right" json:"marginRight"` }
func DefaultPageParameters() PageParameters
DefaultPageParameters creates default parameters.
func (p *PageParameters) Validate() error
Validate checks if the parameters are valid.
Query is a structure that contains query parameters and the content used for the HTMLConverter conversion process.
type Query struct { Content []byte ContentType string URL string Method string PageParameters PageParameters RenderParameters RenderParameters TimeoutDuration time.Duration }
func (h *Query) Validate() error
Validate checks if provided Query is valid.
QueryBuilder is the query that converts HTMLConverter defined data
type QueryBuilder struct {
// contains filtered or unexported fields
}
func BuildHTMLQuery() *QueryBuilder
BuildHTMLQuery creates a Query builder that is supposed to create valid
func (h *QueryBuilder) Err() error
Err gets the error which could occur in the query.
func (h *QueryBuilder) Landscape() *QueryBuilder
Landscape sets up the landscape portrait orientation.
func (h *QueryBuilder) MarginBottom(marginBottom sizes.Length) *QueryBuilder
MarginBottom sets up the MarginBottom parameter for the query.
func (h *QueryBuilder) MarginLeft(marginLeft sizes.Length) *QueryBuilder
MarginLeft sets up the MarginLeft parameter for the query.
func (h *QueryBuilder) MarginRight(marginRight sizes.Length) *QueryBuilder
MarginRight sets up the MarginRight parameter for the query.
func (h *QueryBuilder) MarginTop(marginTop sizes.Length) *QueryBuilder
MarginTop sets up the MarginTop parameter for the query.
func (h *QueryBuilder) Orientation(orientation sizes.Orientation) *QueryBuilder
Orientation sets the page orientation for the Query.
func (h *QueryBuilder) PageSize(pageSize sizes.PageSize) *QueryBuilder
PageSize sets up the PageSize parameter for the query.
func (h *QueryBuilder) PaperHeight(paperHeight sizes.Length) *QueryBuilder
PaperHeight sets up the PaperHeight (in cm) parameter for the query.
func (h *QueryBuilder) PaperWidth(paperWidth sizes.Length) *QueryBuilder
PaperWidth sets up the PaperWidth (in cm) parameter for the query.
func (h *QueryBuilder) Portrait() *QueryBuilder
Portrait sets up the portrait page orientation.
func (h *QueryBuilder) Query() (*Query, error)
Query gets the Query from provided query builder. If some error occurred during build process or the input is not valid the function would return an error.
func (h *QueryBuilder) SetContent(content content.Content) *QueryBuilder
SetContent sets custom data with it's content type.
func (h *QueryBuilder) TimeoutDuration(d time.Duration) *QueryBuilder
TimeoutDuration sets the server query duration timeout. Once the timeout is reached the server will return an error.
func (h *QueryBuilder) Validate() error
Validate checks if the QueryBuilder had no errors during composition and creation.
func (h *QueryBuilder) WaitReady(selector string, by selector.ByType) *QueryBuilder
WaitReady waits for the selector to get ready - 'loaded'.
func (h *QueryBuilder) WaitTime(d time.Duration) *QueryBuilder
WaitTime sets the minimum load time parameter for the page rendering.
func (h *QueryBuilder) WaitVisible(selector string, by selector.ByType) *QueryBuilder
WaitVisible waits for the selector to get visible.
RenderParameters are the parameters related with the rendering.
type RenderParameters struct { WaitTime time.Duration `schema:"minimum-load-time" json:"waitTime"` WaitReady []BySelector `json:"waitReady"` WaitVisible []BySelector `json:"waitVisible"` }
func (p *RenderParameters) Validate() error
Validate checks the validity of the RenderParameters.