web

package
v0.0.0-...-c354ab8 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2014 License: MIT, MIT Imports: 12 Imported by: 0

README

web.Context

hoisie web.go's Context for Martini.

API Reference

Description

web.Context provides a web.go compitable layer for reusing the code written with hoisie's web.go framework. Here compitable means we can use web.Context the same way as in hoisie's web.go but not the others.

Usage

package main

import (
   "github.com/codegangsta/martini"
   "github.com/codegangsta/martini-contrib/web"
 )

func main() {
  m := martini.Classic()
  m.Use(web.ContextWithCookieSecret(""))

  m.Post("/hello", func(ctx *web.Context){
  	  ctx.WriteString("Hello World!")
  })

  m.Run()
}

Authors

Documentation

Overview

Package web provides a web.go compitable layer for reusing the code written with hoisie's `web.go` framework. Basiclly this package add web.Context to martini's dependency injection system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithCookieSecret

func ContextWithCookieSecret(secret string) martini.Handler

if cookie secret is set to "", then SetSecureCookie would not work

func NewCookie

func NewCookie(name string, value string, age int64) *http.Cookie

NewCookie is a helper method that returns a new http.Cookie object. Duration is specified in seconds. If the duration is zero, the cookie is permanent. This can be used in conjunction with ctx.SetCookie.

Types

type Context

type Context struct {
	Request *http.Request
	Params  map[string]string

	http.ResponseWriter
	// contains filtered or unexported fields
}

A Context object is created for every incoming HTTP request, and is passed to handlers as an optional first argument. It provides information about the request, including the http.Request object, the GET and POST params, and acts as a Writer for the response.

func (*Context) Abort

func (ctx *Context) Abort(status int, body string)

Abort is a helper method that sends an HTTP header and an optional body. It is useful for returning 4xx or 5xx errors. Once it has been called, any return value from the handler will not be written to the response.

func (*Context) ContentType

func (ctx *Context) ContentType(val string) string

ContentType sets the Content-Type header for an HTTP response. For example, ctx.ContentType("json") sets the content-type to "application/json" If the supplied value contains a slash (/) it is set as the Content-Type verbatim. The return value is the content type as it was set, or an empty string if none was found.

func (*Context) Forbidden

func (ctx *Context) Forbidden()

Forbidden writes a 403 HTTP response

func (*Context) GetSecureCookie

func (ctx *Context) GetSecureCookie(name string) (string, bool)

func (*Context) NotFound

func (ctx *Context) NotFound(message string)

NotFound writes a 404 HTTP response

func (*Context) NotModified

func (ctx *Context) NotModified()

Notmodified writes a 304 HTTP response

func (*Context) Redirect

func (ctx *Context) Redirect(status int, url_ string)

Redirect is a helper method for 3xx redirects.

func (*Context) SetCookie

func (ctx *Context) SetCookie(cookie *http.Cookie)

SetCookie adds a cookie header to the response.

func (*Context) SetHeader

func (ctx *Context) SetHeader(hdr string, val string, unique bool)

SetHeader sets a response header. If `unique` is true, the current value of that header will be overwritten . If false, it will be appended.

func (*Context) SetSecureCookie

func (ctx *Context) SetSecureCookie(name string, val string, age int64)

func (*Context) Unauthorized

func (ctx *Context) Unauthorized()

Unauthorized writes a 401 HTTP response

func (*Context) WriteString

func (ctx *Context) WriteString(content string)

WriteString writes string data into the response object.

Jump to

Keyboard shortcuts

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