gow

package module
v0.0.0-...-225d712 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

README

gow

🙄 gow!!! the micro web framework.

Hello Gow

g := gow.Me()
g.Get("/", func(ctx gow.Context) {
    ctx.Text("Hello World")
})
g.Listen(":10777")

Template

g := gow.Me()
g.Get("/", func(ctx gow.Context) {
    fmap := template.FuncMap{
        "Name": "gow",
    }
    ctx.Render("index", fmap)
})

JSON

g := gow.Me()
g.Get("/", func(ctx gow.Context) {
    fmap := template.FuncMap{
        "u1": "jack1",
        "u2": "jack2",
        "u3": "jack3",
    }
    ctx.Json(fmap)
})

后续计划

  • session管理
  • 参数优化
  • 多模板支持
  • 配置优化
  • 命令行支持

Documentation

Index

Constants

View Source
const (
	RequestMethodANY     = RequestMethod("ANY")
	RequestMethodGet     = RequestMethod("GET")
	RequestMethodPost    = RequestMethod("POST")
	RequestMethodPut     = RequestMethod("PUT")
	RequestMethodDelete  = RequestMethod("DELETE")
	RequestMethodPatch   = RequestMethod("PATCH")
	RequestMethodHead    = RequestMethod("HEAD")
	RequestMethodOptions = RequestMethod("OPTIONS")

	NOT_FOUND   = "not_found"
	STATIC_RES  = "static_resource"
	BEFORE_EXEC = "before_exec"
	AFTER_EXEC  = "after_exec"
)
View Source
const (
	COMM_TPL_COMMONS  = "commons"
	COMM_TPL_INCLUDES = "includes"
	COMM_TPL_LAYOUTS  = "layouts"
)

Variables

This section is empty.

Functions

func ParsePattern

func ParsePattern(pattern string) (regex *regexp.Regexp, params []string)

Types

type Context

type Context interface {
	Base() string
	Header(key string, value ...string) string
	Host() string
	Ip() string
	Url() string
	Uri() string
	Ext() string
	Method() string
	UserAgent() string
	Referer() string
	IsSSL() bool
	IsAjax() bool
	Request() *http.Request
	Response() *Response
	Text(text string)
	Param(key string) string
	QueryParam(key string) string
	Input() map[string]string
	String(key string) string
	Strings(key string) []string
	Flash(key string, v ...interface{}) interface{}

	SetBody(body []byte)
	Status(code int)
	Json(data interface{})
	ContentType(contentType string)
	Render(tpl string, model map[string]interface{})
	Tpl(tpl string, data map[string]interface{}) string
}

func NewContext

func NewContext(w http.ResponseWriter, req *http.Request) Context

type Gow

type Gow struct {
	Router
	DisableHTTP2 bool
	Dev          bool
	Server       *http.Server
	TLSServer    *http.Server
	Listener     net.Listener
	TLSListener  net.Listener
	Pool         sync.Pool
	Host         string
	Port         int
	TplEngine    *TemplateEngine
}

func Me

func Me() *Gow

func (*Gow) Config

func (g *Gow) Config() *Gow

func (*Gow) Init

func (g *Gow) Init()

func (*Gow) Listen

func (g *Gow) Listen(addr ...string)

func (*Gow) Logger

func (g *Gow) Logger() *log.Logger

func (*Gow) StartServer

func (g *Gow) StartServer(s *http.Server) (err error)

StartServer starts a custom http server.

type Handler

type Handler func(Context)

type RequestMethod

type RequestMethod string

type Response

type Response struct {
	http.ResponseWriter

	Status      int
	IsInterrupt bool
	IsCommit    bool
	Body        []byte
	Headers     map[string]string
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

func (*Response) Commit

func (res *Response) Commit()

func (*Response) ContentType

func (res *Response) ContentType(contentType string)

ContentType sets content-type string.

func (*Response) Cookie

func (res *Response) Cookie(key string, value ...string) string

Cookie gets cookie value by given key when give only string. Cookie sets cookie value by given key, value and expire time string.

func (*Response) Download

func (res *Response) Download(file string)

Download sends file download response by file path.

func (*Response) Interrupt

func (res *Response) Interrupt()

func (*Response) Json

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

Json set json response with data and proper header.

func (*Response) Redirect

func (res *Response) Redirect(url string, status ...int)

Redirect does redirection response to url string and status int optional.

func (*Response) Text

func (res *Response) Text(str string)

func (*Response) Throw

func (res *Response) Throw(status int)

func (*Response) Xml

func (res *Response) Xml(data interface{})

Xml render

type Route

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

type Router

type Router struct {
	Lock sync.RWMutex
	// contains filtered or unexported fields
}

func (*Router) Add

func (r *Router) Add(method RequestMethod, pattern string, fn ...Handler) *Router

func (*Router) After

func (r *Router) After(h Handler) *Router

func (*Router) ApplyStatic

func (r *Router) ApplyStatic()

func (*Router) Before

func (r *Router) Before(h Handler) *Router

func (*Router) Delete

func (r *Router) Delete(pattern string, fn ...Handler) *Router

func (*Router) Find

func (rt *Router) Find(url string, method string) (params map[string]string, fn []Handler)

Find does find matched rule and parse route url, returns route params and matched handlers.

func (*Router) Get

func (r *Router) Get(pattern string, fn ...Handler) *Router

func (*Router) NotFound

func (r *Router) NotFound(h Handler) *Router

func (*Router) Post

func (r *Router) Post(pattern string, fn ...Handler) *Router

func (*Router) Put

func (r *Router) Put(pattern string, fn ...Handler) *Router

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Static

func (r *Router) Static(v ...string) *Router

func (*Router) Use

func (r *Router) Use(m ...Handler) *Router

type TemplateEngine

type TemplateEngine struct {
	Cached bool
	IsInit bool
	// contains filtered or unexported fields
}

func NewTemplateEngine

func NewTemplateEngine() *TemplateEngine

func (*TemplateEngine) CloseCache

func (tple *TemplateEngine) CloseCache()

close template cache

func (*TemplateEngine) CreateTemplate

func (tple *TemplateEngine) CreateTemplate(tplName string) *template.Template

func (*TemplateEngine) Init

func (tple *TemplateEngine) Init()

func (*TemplateEngine) Render

func (tple *TemplateEngine) Render(tplName string, data map[string]interface{}) (b []byte, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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