crater

package module
v0.0.0-...-b9af339 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2013 License: MIT Imports: 12 Imported by: 0

README

##Crater Build Status GoDoc Web framework for Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateId

func GenerateId() string

GenerateId generates random Id string.

Types

type App

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

App represents you web application, which has a settings and handlers.

func NewApp

func NewApp() App

NewApp creates a new instance of App. It uses default settings for application. Settings can be updated using Settings method.

func (*App) Delete

func (app *App) Delete(url string, handler handlerFunc)

Delete adds a route for HTTP DELETE request.

func (*App) Get

func (app *App) Get(url string, handler handlerFunc)

Get adds a route for HTTP GET request

func (*App) Listen

func (app *App) Listen(serverURL string)

Listen listens on the TCP network address and then calls handler corresponding the request url to handle requests on incoming connections.

func (*App) NotFound

func (app *App) NotFound(handler handlerFunc)

NotFound overrides 404 status result. It will be called when no routes match request url.

func (*App) Post

func (app *App) Post(url string, handler handlerFunc)

Post adds a route for HTTP POST request.

func (*App) Put

func (app *App) Put(url string, handler handlerFunc)

Put adds a route for HTTP PUT request.

func (*App) Settings

func (app *App) Settings(settings *Settings)

Settings sets settings of application.

func (*App) Static

func (app *App) Static(url string)

Static handles Static files (js, css, images).

func (*App) Use

func (app *App) Use(handler handlerFunc)

Use adds new middleware for your application. Middleware is a handler which is called before every request.

type Request

type Request struct {
	*http.Request
	// RouteParams is key-value pairs of route parameters.
	// If you route is "/category/{id}" and request url is "/category/1",
	// RouteParams will contain "id" => "1".
	RouteParams map[string]string
	// Session have a session data for current user.
	Session *Session
}

Request contains current request data.

func (*Request) Parse

func (req *Request) Parse(s interface{}) error

Parse converts request data (json or form values) to the struct type.

type Response

type Response struct {
	Header http.Header
	// contains filtered or unexported fields
}

Response sends data to the client.

func (*Response) Json

func (res *Response) Json(model interface{})

Json send json to response.

func (*Response) Redirect

func (res *Response) Redirect(url string)

Redirect redirects to specified url (with code 302).

func (*Response) Render

func (res *Response) Render(viewName string, model interface{})

Render parse given html using model and send to response. It use html/template to parse html

func (*Response) RenderTemplate

func (res *Response) RenderTemplate(templateName string, model interface{})

RenderTemplate parse given template by name using model and send to response. Template should be defined as {{ define "name" }} ... {{ end }}.

func (*Response) Send

func (res *Response) Send(str string)

Send sends string to response.

func (*Response) SetCookie

func (res *Response) SetCookie(cookie *http.Cookie)

SetCookie write a cookie to the response.

func (*Response) WriteHeader

func (res *Response) WriteHeader(code int)

WriteHeader sends an HTTP response header with status code.

type Session

type Session struct {
	Id      string
	Value   interface{}
	Expires time.Time
	// contains filtered or unexported fields
}

Session represents current session and its data.

func (*Session) Abandon

func (session *Session) Abandon()

Abandon end current session

type SessionManager

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

SessionManager manage session for current request.

func NewSessionManager

func NewSessionManager(store SessionStore, timeout time.Duration) *SessionManager

NewSessionManager creates new instance of SessionManager.

func (*SessionManager) GetSession

func (manager *SessionManager) GetSession(req *Request, res *Response) *Session

GetSession returns session for current request. If there is no session, it will be created.

type SessionStore

type SessionStore interface {
	Get(id string) *Session
	New(id string, session *Session)
	Delete(id string)
}

SessionStore is an interface which allow to implement custom session store.

type Settings

type Settings struct {
	// Path to the root folder with html files.
	ViewsPath string
	// Path to the root folder with static content (js, css, images).
	StaticPath string
	// Extension of the View files or templates.
	ViewExtension string
}

Settings represent application settings.

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings creates a settings object with default settings.

func (*Settings) Update

func (settings *Settings) Update(newSettings *Settings)

Update updates current settings with passed settings data. If settings filed is empty, default value with be used for this field.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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