package module
Version: v0.0.0-...-9d008c5 Latest Latest

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

Go to latest
Published: Dec 9, 2019 License: MIT Imports: 10 Imported by: 0



Golang connector for Seo4Ajax GoDoc.

Code and tests is highly adapted from connect middleware.

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    if seo4ajax.IsPrerender(r) {
        err := seo4ajax.GetPrerenderedPage(w, r)
        if err != nil {
    } else {
        fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))



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



This section is empty.


View Source
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

func IsPrerender(r *http.Request) bool

IsPrerender returns true, when Seo4Ajax shall be used for the given http Request. The logic is taken from


type Client

type Client struct {
	// contains filtered or unexported fields

Client is the Seo4Ajax Client

func New

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

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

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
	Token     string        // seo4ajax token, must be set
	IP        string        // server IP, defaults to
	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

Source Files

Jump to

Keyboard shortcuts

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