mano

package module
Version: v0.0.0-...-ed3c113 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

README

mano License Build Status

An web framework for Go

Documentation

Installation

$ go get -u -v github.com/junhwong/mano

Usage


Changelog

Details changes for each release are documented in the release notes.

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

Apache-2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRouters = &RouterGroup{
	pattern: "/",
	routers: make([]*Router, 0),
	groups:  make([]*RouterGroup, 0),
}

DefaultRoutes 是用于收集默认路由的集合

Functions

func Group

func Group(pattern string, controller interface{})

Types

type ActionView

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

func (*ActionView) ContentType

func (v *ActionView) ContentType() string

type Application

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

Application ...

func Default

func Default() *Application

Default returns a default(global) Engine instance.

func New

func New() *Application

New returns a new Application.

func (*Application) AddMiddleware

func (app *Application) AddMiddleware(name string, ware Middleware, global ...bool)

AddMiddleware method add a Middleware to Application.

func (*Application) Attr

func (app *Application) Attr(key string, defaultValue ...string) string

func (*Application) Items

func (app *Application) Items() utils.Attribute

func (*Application) Run

func (app *Application) Run(addr ...string) (err error)

Run attaches the router to a http.Server and starts listening and serving HTTP requests. It is a shortcut for http.ListenAndServe(addr, router) Note: this method will block the calling goroutine indefinitely unless an error happens.

func (*Application) ServeHTTP

func (app *Application) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP is implements for http.Handler interface

func (*Application) Use

func (app *Application) Use(registrations ...interface{})

Use 设置或注册全局变量、中间件、服务等

type ContentView

type ContentView struct {
	*ActionView
	Content string
}

func (*ContentView) Render

func (ar *ContentView) Render(ctx Context) error

type Context

type Context interface {
	App() *Application

	//Response 返回响应写入器
	Response() *Response

	Request() *Request

	// Attr Gets or sets the HttpApplication object for the current HTTP request.
	Attr(name string, value ...interface{}) interface{}

	// Data Gets or sets the Context object for the current HTTP request.
	Data(name string, value ...interface{}) interface{}
	ViewData() map[string]interface{}

	//PathValue returns a route path data with given name
	PathValue(name string) (value string, ok bool)

	Param(name string) string

	Content(content string, contentType ...string) View
	JSON(data interface{}, contentType ...string) View
	Empty() View
	View(template string, contentType ...string) View
}

Context Encapsulates all HTTP-specific information about an individual HTTP request.

type GoTemplateViewEngine

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

func GoTemplate

func GoTemplate(ilpath string) *GoTemplateViewEngine

GoTemplate 将使用 GO 原生模板技术作为视图引擎

func (*GoTemplateViewEngine) Render

func (engine *GoTemplateViewEngine) Render(data map[string]interface{}, path string, out io.Writer) error

type HTTPHandler

type HTTPHandler interface {
	Init(app *Application) error
	Handle(writer http.ResponseWriter, request *http.Request) (complated bool, err error)
}

HTTPHandler is HTTP处理程序

type Handler

type Handler interface{}

type HandlerFunc

type HandlerFunc func(Context) interface{}

type HttpMethod

type HttpMethod uint8
const (
	DENY    HttpMethod = iota
	OPTIONS HttpMethod = iota * iota
	GET
	HEAD
	POST
	PUT
	DELETE
	TRACE
	CONNECT
	ALL
)

func ParseHttpMethod

func ParseHttpMethod(method string) HttpMethod

func (HttpMethod) In

func (m HttpMethod) In(method HttpMethod) bool

type I18N

type I18N interface {
	Lang(local, name string, args ...interface{}) (lang string)
}

type JsonView

type JsonView struct {
	*ActionView
	Data interface{}
}

func (*JsonView) Render

func (v *JsonView) Render(ctx Context) error

type Middleware

type Middleware interface {
	Handle(Context, Middleware) interface{}
}

type OtplViewEngine

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

func Otpl

func Otpl(ilpath string) *OtplViewEngine

Otpl 视图引擎

func (*OtplViewEngine) Render

func (engine *OtplViewEngine) Render(data map[string]interface{}, path string, out io.Writer) error

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request is a http.Request wrapper.

func (*Request) Cookie

func (r *Request) Cookie(name string) string

func (*Request) Cookies

func (r *Request) Cookies() []*http.Cookie

func (*Request) Query

func (r *Request) Query(name string) string

func (*Request) RawRequest

func (req *Request) RawRequest() *http.Request

TODO:APIs Form FormValue() FormFile()

type RequestContext

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

func (*RequestContext) App

func (ctx *RequestContext) App() *Application

func (*RequestContext) Attr

func (ctx *RequestContext) Attr(name string, value ...interface{}) interface{}

func (*RequestContext) Content

func (ctx *RequestContext) Content(content string, contentType ...string) View

func (*RequestContext) Data

func (ctx *RequestContext) Data(name string, value ...interface{}) interface{}

func (*RequestContext) Empty

func (ctx *RequestContext) Empty() View

func (*RequestContext) JSON

func (ctx *RequestContext) JSON(data interface{}, contentType ...string) View

func (*RequestContext) Param

func (ctx *RequestContext) Param(name string) string

func (*RequestContext) PathValue

func (ctx *RequestContext) PathValue(name string) (value string, ok bool)

func (*RequestContext) Request

func (ctx *RequestContext) Request() *Request

func (*RequestContext) Response

func (ctx *RequestContext) Response() *Response

func (*RequestContext) View

func (ctx *RequestContext) View(template string, contentType ...string) View

func (*RequestContext) ViewData

func (ctx *RequestContext) ViewData() map[string]interface{}

type Response

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

func (*Response) AddCookie

func (r *Response) AddCookie(c *http.Cookie)

AddCookie adds a cookie to the response.

func (*Response) AppendHeader

func (r *Response) AppendHeader(key, value string) *Response

func (*Response) Writer

func (r *Response) Writer() http.ResponseWriter

type RouteData

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

type RouteEntry

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

type RouteHandler

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

func URLRouting

func URLRouting(prefix ...string) *RouteHandler

func (*RouteHandler) Handle

func (handler *RouteHandler) Handle(writer http.ResponseWriter, request *http.Request) (complated bool, err error)

func (*RouteHandler) Init

func (handler *RouteHandler) Init(app *Application) error

type RouteTable

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

func (*RouteTable) Match

func (rt *RouteTable) Match(method HttpMethod, url *url.URL) (*RouteData, bool)

Match 匹配

func (*RouteTable) Register

func (rt *RouteTable) Register(method HttpMethod, pattern *regexp.Regexp, paramNames []string, handler HandlerFunc, segments int, endsWildcard bool, middlewares ...Middleware)

type Router

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

func Get

func Get(pattern string, handler Handler, middlewares ...string) *Router

Get registers a new GET request handle and middleware with the given pattern.

type RouterGroup

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

func NewGroup

func NewGroup(pattern string, middlewares ...string) *RouterGroup

func (*RouterGroup) AppendController

func (group *RouterGroup) AppendController(controller interface{}) *RouterGroup

func (*RouterGroup) Get

func (group *RouterGroup) Get(pattern string, handler Handler, middlewares ...string) *Router

func (*RouterGroup) Group

func (group *RouterGroup) Group(pattern string, controller interface{}, middlewares ...string) *RouterGroup

func (*RouterGroup) Route

func (group *RouterGroup) Route(method HttpMethod, pattern string, handler Handler, middlewares []string) *Router

type ServiceFunc

type ServiceFunc func(Context) reflect.Value

type StaticFileHandler

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

func Static

func Static(root, prefix string, suffix ...string) *StaticFileHandler

func (*StaticFileHandler) Handle

func (handler *StaticFileHandler) Handle(writer http.ResponseWriter, request *http.Request) (complated bool, err error)

func (*StaticFileHandler) Init

func (handler *StaticFileHandler) Init(app *Application) error

type TemplateView

type TemplateView struct {
	*ActionView
	Template string
}

func (*TemplateView) Render

func (v *TemplateView) Render(ctx Context) error

type View

type View interface {
	// ContentType returns HTTP Content-type
	ContentType() string
	// Render the view given the specified model.
	Render(ctx Context) error
}

View for a web interaction. Implementations are responsible for rendering content, and exposing the model.

type ViewEngine

type ViewEngine interface {
	Render(data map[string]interface{}, path string, out io.Writer) error
}

ViewEngine 提供用于将特定模板为渲染为相应输出格式的一组方法

Directories

Path Synopsis
aes
opc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL