turbo

package module
v0.0.0-...-50e715b Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2018 License: MIT Imports: 11 Imported by: 0

README

Turbo CircleCI

Turbo is a Go backend for Basecamp's Turbolinks.

Usage

Wrap an http.Handler in turbo.Handler, ie:

package main

import (
    "net/http"

    "github.com/bentranter/turbo"
)

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("hey"))
    })
    http.ListenAndServe(":3000", turbo.Handler(mux))
}

Documentation

Overview

Package turbo provides everything you need for creating Turbolinks-style frontend applications.

TODO(ben) Stuff we need:

  • tubro.CSRF for CSRF (obv)

Index

Constants

View Source
const (
	// TurbolinksReferrer is the header sent by the Turbolinks frontend on any
	// XHR requests powered by Turbolinks. We use this header to detect if the
	// current request was sent from Turbolinks.
	TurbolinksReferrer = "Turbolinks-Referrer"

	// TurbolinksCookie is the name of the cookie that we use to handle
	// redirect requests correctly.
	//
	// We name it `_turbolinks_location` to be consistent with the name Rails
	// give to the cookie that serves the same purpose.
	TurbolinksCookie = "_turbolinks_location"

	// DefaultFlashCookieName is the default name for the cookie containing
	// flash messages.
	DefaultFlashCookieName = "_turbo_message"
)
View Source
const (
	DefaultLeftDelim  = "{{"
	DefaultRightDelim = "}}"
)

Variables

This section is empty.

Functions

func Handler

func Handler(h http.Handler) http.Handler

Handler is a middleware wrapper for Turbolinks.

func IsTLS

func IsTLS(r *http.Request) bool

IsTLS is a helper to check if a requets was performed over HTTPS.

Types

type Options

type Options struct {
	Directory     string
	Layout        string
	Extensions    []string
	Funcs         []template.FuncMap
	IsDevelopment bool
}

type Render

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

func New

func New(opts ...Options) *Render

func (*Render) Flash

func (r *Render) Flash(w http.ResponseWriter, message string)

Flash sets a flash message on the given response.

func (*Render) GetFlash

func (r *Render) GetFlash(w http.ResponseWriter, req *http.Request) string

GetFlash retrieves the flash message the given request.

func (*Render) HTML

func (r *Render) HTML(w http.ResponseWriter, req *http.Request, status int, name string, binding interface{}, partial ...bool) error

HTML renders an HTML template.

If the partial option is passed as true, the template will render without its layout.

func (*Render) Redirect

func (r *Render) Redirect(w http.ResponseWriter, req *http.Request, url string, notice ...string)

Redirect redirects the user to the given URL. If a message is provided, it will be set as a flash message on the response.

func (*Render) String

func (r *Render) String(w http.ResponseWriter, req *http.Request, name string, binding interface{}, partial ...bool) (string, error)

String renders an HTML template to a string.

If the partial option is passed as true, the template will render without its layout.

func (*Render) TemplateLookup

func (r *Render) TemplateLookup(t string) *template.Template

TemplateLookup is a wrapper around template.Lookup and returns the template with the given name that is associated with t, or nil if there is no such template.

Jump to

Keyboard shortcuts

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