Documentation ¶
Index ¶
- type App
- func (app *App) Delete(pattern string, handler RequestHandler) error
- func (app *App) Get(pattern string, handler RequestHandler) error
- func (app *App) Listen(port uint32) error
- func (app *App) Patch(pattern string, handler RequestHandler) error
- func (app *App) Post(pattern string, handler RequestHandler) error
- func (app *App) Put(pattern string, handler RequestHandler) error
- func (app *App) RegisterPatternHandler(handler PatternHandler)
- func (app *App) SetStaticDir(dir string)
- func (app *App) SetViewDir(dir string)
- func (app *App) SetViewType(viewType ENUM_VIEW_TYPE) error
- type AppSettings
- type ENUM_VIEW_TYPE
- type HTTPMethod
- type HandlersMap
- type KeyValues
- func (vp *KeyValues) Get(k string) (interface{}, error)
- func (vp *KeyValues) GetAsList(k string) (*list.List, error)
- func (vp *KeyValues) GetAsString(k string) (string, error)
- func (vp *KeyValues) GetKeys() []string
- func (vp *KeyValues) PutFloat(k string, v float64)
- func (vp *KeyValues) PutInt(k string, v int)
- func (vp *KeyValues) PutList(k string, v *list.List)
- func (vp *KeyValues) PutString(k string, v string)
- type PatternHandler
- type Request
- type RequestHandler
- type Response
- func (res *Response) Flush() error
- func (res *Response) Render(templateRelativePath string, viewParams *KeyValues) (string, error)
- func (res *Response) SetHeader(key string, value string)
- func (res *Response) SetHeaders(params ...interface{}) error
- func (res *Response) SetStatusCode(code int)
- func (res *Response) WriteJSON(value interface{}) error
- func (res *Response) WriteString(value string)
- type ViewEngine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App stands for a application which applies some http services.
func (*App) Delete ¶
func (app *App) Delete(pattern string, handler RequestHandler) error
Delete handles the http request whose request method is "DELETE".
func (*App) Get ¶
func (app *App) Get(pattern string, handler RequestHandler) error
Get handles the http request whose request method is "GET".
func (*App) Patch ¶
func (app *App) Patch(pattern string, handler RequestHandler) error
Patch handles the http request whose request method is "PATCH".
func (*App) Post ¶
func (app *App) Post(pattern string, handler RequestHandler) error
Post handles the http request whose request method is "POST".
func (*App) Put ¶
func (app *App) Put(pattern string, handler RequestHandler) error
Put handles the http request whose request method is "PUT".
func (*App) RegisterPatternHandler ¶
func (app *App) RegisterPatternHandler(handler PatternHandler)
RegisterPatternHandler registers your own PatternHandler. See pattern.go for more details.
func (*App) SetStaticDir ¶
SetStaticDir sets the static resource directory. Typically, you can put the js, css and img folder in the static resource directory.
func (*App) SetViewDir ¶
SetViewDir sets the view directory. You should put all your view templates in the view directory.
func (*App) SetViewType ¶
func (app *App) SetViewType(viewType ENUM_VIEW_TYPE) error
SetViewType sets the view type. See ENUM_VIEW_TYPE in view.go for more details.
type AppSettings ¶
type AppSettings struct { // The ViewEngine you have choose. View ViewEngine // The view directory you have choose. ViewDir string // The static resource directory you have choose. StaticDir string }
AppSettings records the current settings.
type ENUM_VIEW_TYPE ¶
type ENUM_VIEW_TYPE byte
ENUM_VIEW_TYPE is a wrapper type for view-type.
const ( // VIEW_NULL means there's no need to use view. VIEW_NULL ENUM_VIEW_TYPE = iota // VIEW_EGO is a view template that like the ejs in node.js Express framework. VIEW_EGO )
type HTTPMethod ¶
type HTTPMethod string
HTTPMethod is a wrapper type for http method string.
const ( // HTTP_GET is the "GET" http method HTTP_GET HTTPMethod = "GET" // HTTP_POST is the "POST" http method HTTP_POST HTTPMethod = "POST" // HTTP_PUT is the "PUT" http method HTTP_PUT HTTPMethod = "PUT" // HTTP_DELETE is the "DELETE" http method HTTP_DELETE HTTPMethod = "DELETE" // HTTP_PATCH is the "PATCH" http method HTTP_PATCH HTTPMethod = "PATCH" )
type HandlersMap ¶
type HandlersMap map[HTTPMethod]map[string]RequestHandler
HandlersMap is a map that matches the request url and it's handler in a http method.
func (HandlersMap) GetHandler ¶
func (hm HandlersMap) GetHandler(method HTTPMethod, pattern string) RequestHandler
GetHandler gets the handler matches the request method and url.
func (HandlersMap) GetPatterns ¶
func (hm HandlersMap) GetPatterns(method HTTPMethod) []string
GetPatterns gets the pattern(url) list in a http method.
type KeyValues ¶
type KeyValues map[string]interface{}
KeyValues is an utility that helps to make the key-value pairs more comfortably.
func NewKeyValues ¶
NewKeyValues returns a new KeyValues instance. Example: keyValues := NewKeyValues(
"key1", 1, "key2", "key2value", "key3", 1.23456
)
func (*KeyValues) GetAsList ¶
GetAsList gets the value by key and convert the value to the *list.List type, it will return an error if convert failed.
func (*KeyValues) GetAsString ¶
GetAsString gets the value by key and convert the value to the string type, it will return an error if convert failed.
type PatternHandler ¶
type PatternHandler interface { // HandlePattern will return two boolean values. // The first boolean value points if the pattern handled. // The second boolean value points if we should continue. HandlePattern(req *http.Request, res http.ResponseWriter, handlersMap HandlersMap, settings *AppSettings) (bool, bool) }
PatternHandler interface helps people make their own PatterHandler to handle the special url format, such as /user/:username (it's an build-in pattern handler).
type RequestHandler ¶
RequestHandler interface helps people to make their own request handler.
type Response ¶
type Response struct { http.ResponseWriter // contains filtered or unexported fields }
Response object stands for a http response.
func (*Response) SetHeaders ¶
SetHeaders sets the response headers.
func (*Response) SetStatusCode ¶
SetStatusCode sets the status code of response.
func (*Response) WriteJSON ¶
WriteJSON writes json data to the response cache. The response won't be send util you call the Flush() method.
func (*Response) WriteString ¶
WriteString writes string data to the response cache. The response won't be send util you call the Flush() method.