HomeUniDoc
...

Package client

Overview ▾

Package client contains HTML Converter HTTP Client. The Client implements htmlcreator.HTMLConverter interface for the UniPDF module and can be used as a plugin for the UniPDF creator.Creator.

Index ▾

Variables
type BySelector
    func (b BySelector) Validate() error
type Client
    func New(o Options) *Client
    func (c *Client) ConvertHTML(ctx context.Context, q *Query) (*PDFResponse, error)
    func (c *Client) HealthCheck(ctx context.Context) error
type Option
    func WithDefaultTimeout(option time.Duration) Option
    func WithHTTPS(useHTTPS bool) Option
    func WithHostname(option string) Option
    func WithPort(option int) Option
    func WithPrefix(prefix string) Option
type Options
    func ParseOptions(connectPath string) (Options, error)
    func (o *Options) Addr() string
type PDFResponse
type PageParameters
    func DefaultPageParameters() PageParameters
    func (p *PageParameters) Validate() error
type Query
    func (h *Query) Validate() error
type QueryBuilder
    func BuildHTMLQuery() *QueryBuilder
    func (h *QueryBuilder) Err() error
    func (h *QueryBuilder) Landscape() *QueryBuilder
    func (h *QueryBuilder) MarginBottom(marginBottom sizes.Length) *QueryBuilder
    func (h *QueryBuilder) MarginLeft(marginLeft sizes.Length) *QueryBuilder
    func (h *QueryBuilder) MarginRight(marginRight sizes.Length) *QueryBuilder
    func (h *QueryBuilder) MarginTop(marginTop sizes.Length) *QueryBuilder
    func (h *QueryBuilder) Orientation(orientation sizes.Orientation) *QueryBuilder
    func (h *QueryBuilder) PageSize(pageSize sizes.PageSize) *QueryBuilder
    func (h *QueryBuilder) PaperHeight(paperHeight sizes.Length) *QueryBuilder
    func (h *QueryBuilder) PaperWidth(paperWidth sizes.Length) *QueryBuilder
    func (h *QueryBuilder) Portrait() *QueryBuilder
    func (h *QueryBuilder) Query() (*Query, error)
    func (h *QueryBuilder) SetContent(content content.Content) *QueryBuilder
    func (h *QueryBuilder) Validate() error
    func (h *QueryBuilder) WaitReady(selector string, by selector.ByType) *QueryBuilder
    func (h *QueryBuilder) WaitTime(d time.Duration) *QueryBuilder
    func (h *QueryBuilder) WaitVisible(selector string, by selector.ByType) *QueryBuilder
type RenderParameters
    func (p *RenderParameters) Validate() error

Package files

client.go doc.go generate.go options.go page_parameters.go query.go

Variables

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.
    ErrUnauthorized = 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")
)

type BySelector

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

func (b BySelector) Validate() error

Validate checks validity of the selector.

type Client

Client is a structure that is a HTTP client for the unihtml server.

type Client struct {
    Options Options
    Client  *http.Client
}

func New

func New(o Options) *Client

New creates new client with provided options.

func (*Client) ConvertHTML

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 (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck connects to the server and check the health status of the server.

type Option

Option is a function that changes client options.

type Option func(o *Options)

func WithDefaultTimeout

func WithDefaultTimeout(option time.Duration) Option

WithDefaultTimeout sets the DefaultTimeout option for the client options.

func WithHTTPS

func WithHTTPS(useHTTPS bool) Option

WithHTTPS sets the TLS option for the client options.

func WithHostname

func WithHostname(option string) Option

WithHostname sets the Hostname option for the client options.

func WithPort

func WithPort(option int) Option

WithPort sets the Port option for the client options.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets the client prefix.

type Options

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

func ParseOptions(connectPath string) (Options, error)

ParseOptions parses options for the Client.

func (*Options) Addr

func (o *Options) Addr() string

Addr gets the HTTP address URI used by the http.Client.

type PDFResponse

PDFResponse is the response used by the HTMLConverter.

type PDFResponse struct {
    ID   string `json:"id"`
    Data []byte `json:"data"`
}

type PageParameters

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

func DefaultPageParameters() PageParameters

DefaultPageParameters creates default parameters.

func (*PageParameters) Validate

func (p *PageParameters) Validate() error

Validate checks if the parameters are valid.

type Query

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
}

func (*Query) Validate

func (h *Query) Validate() error

Validate checks if provided Query is valid.

type QueryBuilder

QueryBuilder is the query that converts HTMLConverter defined data

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

func BuildHTMLQuery

func BuildHTMLQuery() *QueryBuilder

BuildHTMLQuery creates a Query builder that is supposed to create valid

func (*QueryBuilder) Err

func (h *QueryBuilder) Err() error

Err gets the error which could occur in the query.

func (*QueryBuilder) Landscape

func (h *QueryBuilder) Landscape() *QueryBuilder

Landscape sets up the landscape portrait orientation.

func (*QueryBuilder) MarginBottom

func (h *QueryBuilder) MarginBottom(marginBottom sizes.Length) *QueryBuilder

MarginBottom sets up the MarginBottom parameter for the query.

func (*QueryBuilder) MarginLeft

func (h *QueryBuilder) MarginLeft(marginLeft sizes.Length) *QueryBuilder

MarginLeft sets up the MarginLeft parameter for the query.

func (*QueryBuilder) MarginRight

func (h *QueryBuilder) MarginRight(marginRight sizes.Length) *QueryBuilder

MarginRight sets up the MarginRight parameter for the query.

func (*QueryBuilder) MarginTop

func (h *QueryBuilder) MarginTop(marginTop sizes.Length) *QueryBuilder

MarginTop sets up the MarginTop parameter for the query.

func (*QueryBuilder) Orientation

func (h *QueryBuilder) Orientation(orientation sizes.Orientation) *QueryBuilder

Orientation sets the page orientation for the Query.

func (*QueryBuilder) PageSize

func (h *QueryBuilder) PageSize(pageSize sizes.PageSize) *QueryBuilder

PageSize sets up the PageSize parameter for the query.

func (*QueryBuilder) PaperHeight

func (h *QueryBuilder) PaperHeight(paperHeight sizes.Length) *QueryBuilder

PaperHeight sets up the PaperHeight (in cm) parameter for the query.

func (*QueryBuilder) PaperWidth

func (h *QueryBuilder) PaperWidth(paperWidth sizes.Length) *QueryBuilder

PaperWidth sets up the PaperWidth (in cm) parameter for the query.

func (*QueryBuilder) Portrait

func (h *QueryBuilder) Portrait() *QueryBuilder

Portrait sets up the portrait page orientation.

func (*QueryBuilder) Query

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 (*QueryBuilder) SetContent

func (h *QueryBuilder) SetContent(content content.Content) *QueryBuilder

SetContent sets custom data with it's content type.

func (*QueryBuilder) Validate

func (h *QueryBuilder) Validate() error

Validate checks if the QueryBuilder had no errors during composition and creation.

func (*QueryBuilder) WaitReady

func (h *QueryBuilder) WaitReady(selector string, by selector.ByType) *QueryBuilder

WaitReady waits for the selector to get ready - 'loaded'.

func (*QueryBuilder) WaitTime

func (h *QueryBuilder) WaitTime(d time.Duration) *QueryBuilder

WaitTime sets the minimum load time parameter for the page rendering.

func (*QueryBuilder) WaitVisible

func (h *QueryBuilder) WaitVisible(selector string, by selector.ByType) *QueryBuilder

WaitVisible waits for the selector to get visible.

type RenderParameters

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 (*RenderParameters) Validate

func (p *RenderParameters) Validate() error

Validate checks the validity of the RenderParameters.