go-seo4ajax: github.com/justwatchcom/go-seo4ajax Index | Files

package seo4ajax

import "github.com/justwatchcom/go-seo4ajax"

Package seo4ajax provides a library for accessing the SEO4Ajax prerender service. Before using, you need to set ServerIp to a valid IP address.

Index

Package Files

seo4ajax.go

Variables

var (
    // ErrNoToken is returned when the client isn't provided a API token
    ErrNoToken = errors.New("no token given")
    // ErrCacheMiss happens if seo4ajax responded with a cache miss
    ErrCacheMiss = errors.New("cache miss from seo4ajax")
    // ErrUnknownStatus represents an unknown status code
    ErrUnknownStatus = errors.New("Unknown Status Code")
)

func IsPrerender Uses

func IsPrerender(r *http.Request) bool

IsPrerender returns true, when Seo4Ajax shall be used for the given http Request. The logic is taken from https://github.com/seo4ajax/connect-s4a/blob/master/lib/connect-s4a.js

type Client Uses

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

Client is the Seo4Ajax Client

func New Uses

func New(cfg Config) (*Client, error)

New creates a new Seo4Ajax client. Returns an error if no token is provided

func (*Client) GetPrerenderedPage Uses

func (c *Client) GetPrerenderedPage(w http.ResponseWriter, r *http.Request)

GetPrerenderedPage returns the prerendered html from the seo4ajax api

func (*Client) ServeHTTP Uses

func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP will serve the prerendered page if this is a prerender request. If no upstream handler is set it will return an error. Otherwise it will just invoke the upstream handler. This way it can be either used as an HTTP middleware intercepting any prerender requests or an regular HTTP handler (if next is nil) to serve only prerender request

type Config Uses

type Config struct {
    Log       log.Logger
    Next      http.Handler
    Transport http.RoundTripper
    Server    string        // seo4ajax api server, defaults to http://api.seo4ajax.com
    Token     string        // seo4ajax token, must be set
    IP        string        // server IP, defaults to 127.0.0.1
    Timeout   time.Duration // retry timeout, defaults to 30s
    // s4a supports client side caching and returns an empty 304 if the content hasn't changed.
    // If UnconditionalFetch set to true the client side caching headers (If-Modified-Since and If-None-Match)
    // are removed
    UnconditionalFetch bool
    // FetchErrorStatus is the http status code returned if the fetch from seo4ajax fails
    FetchErrorStatus int
    // FetchTimeout is the http timeout for a single fetch attempt
    FetchTimeout time.Duration
    // RetryUnavailable advises the retry loop to retry a fetch on 503 upstream results until success or Timeout
    RetryUnavailable bool
}

Config is the Seo4Ajax Client config

Package seo4ajax imports 10 packages (graph). Updated 2019-12-18. Refresh now. Tools for package owners.