httpview

package
v0.0.0-...-f4c7a8f Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2014 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Helper methods to combine webview templates with http requests objects

Uses the gorilla context library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAliasMap

func GetAliasMap(req *http.Request) map[string]string

Get the alias that will be used to render the template

func GetLayoutName

func GetLayoutName(req *http.Request) string

Return the layout defined, if nothing was set, returns layout/main.html

func GetViewName

func GetViewName(req *http.Request) string

Return the name of the View from the request

func RedirectLocal

func RedirectLocal(req *http.Request, path string)

Set the redirect information for the given request

func RegisterView

func RegisterView(req *http.Request, set webview.TreeSet)

Register the treeset and the alias name for the current request

func Render

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

Render the view configured to that request

This method will redirect if any of the Redirect* methods were called or will try to render the view configured with SetView{Name/Data}

func RenderView

func RenderView(w http.ResponseWriter, req *http.Request, name string, data interface{}) error

Render the given view using the alias and treeset registered for the current request

Use the RegisterView in your http pipeline beforer calling RenderView

func SetAliasMap

func SetAliasMap(req *http.Request, alias map[string]string)

Set the alias that will be used to render the template

func SetLayoutName

func SetLayoutName(req *http.Request, name string)

Set the layout that will be used.

To render the view the layout should call {{ template "contents" }}

func SetViewData

func SetViewData(req *http.Request, data interface{})

Set the data that should be used to render the template

func SetViewName

func SetViewName(req *http.Request, name string)

Set the name of the view that should be rendered at Render

Types

type Reader

type Reader struct {
	Values url.Values
}

Read values from a url.Values object

func (*Reader) Bytes

func (r *Reader) Bytes(name string, def []byte) []byte

Similar to ReadBytes but ignores the ok flag

func (*Reader) Float

func (r *Reader) Float(name string, def float64) float64

Similar to ReadFloat but ignores the ok flag

func (*Reader) Int

func (r *Reader) Int(name string, def int64) int64

Similar to ReadInt but ignores the ok flag

func (*Reader) Read

func (r *Reader) Read(name, def string) (string, bool)

Read a string value form the values object, if no value is found return the default

The boolean flag is true only if the value was read form the map.

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(name string, def []byte) ([]byte, bool)

Similar to Read but returns the string as an array of bytes

func (*Reader) ReadFloat

func (r *Reader) ReadFloat(name string, def float64) (float64, bool)

Similar to ReadInt but returns a float value

func (*Reader) ReadInt

func (r *Reader) ReadInt(name string, def int64) (int64, bool)

Read a integer value from the values object, if no value is found or a value cannot be converted to a integer, return the default

The boolean flag is true only if the value was read from the map and correctly converted

func (*Reader) ReadUint

func (r *Reader) ReadUint(name string, def uint64) (uint64, bool)

Similar to ReadInt but returns a uint value

func (*Reader) Str

func (r *Reader) Str(name string, def string) string

Similar to Read but ignores the ok flag

Jump to

Keyboard shortcuts

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