Documentation ¶
Overview ¶
Package seo4ajax provides a library for accessing the SEO4Ajax prerender service. Before using, you need to set ServerIp to a valid IP address.
Index ¶
Constants ¶
This section is empty.
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") )
Functions ¶
func IsPrerender ¶
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
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Seo4Ajax Client
func (*Client) GetPrerenderedPage ¶
func (c *Client) GetPrerenderedPage(w http.ResponseWriter, r *http.Request)
GetPrerenderedPage returns the prerendered html from the seo4ajax api
func (*Client) ServeHTTP ¶
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 ¶
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 bool }
Config is the Seo4Ajax Client config