gsg

package
v0.0.0-...-94bd766 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// origin objects
	Writer http.ResponseWriter
	Req    *http.Request
	// request info
	Path   string
	Method string
	Params map[string]string
	// response info
	StatusCode int
	// contains filtered or unexported fields
}

Context is the encapsulation of http.ResponseWriter and *http.Request

func (*Context) Data

func (c *Context) Data(code int, data []byte)

Data sets the data for response

func (*Context) Fail

func (c *Context) Fail(code int, err string)

Fail sets the status code and error message for response

func (*Context) HTML

func (c *Context) HTML(code int, name string, data interface{})

HTML sets the html for response

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

JSON sets the json for response

func (*Context) Next

func (c *Context) Next()

Next is used to execute the next middleware

func (*Context) Param

func (c *Context) Param(key string) string

Param returns the path parameter by key

func (*Context) PostForm

func (c *Context) PostForm(key string) string

PostForm is a wrapper of r.PostFormValue()

func (*Context) Query

func (c *Context) Query(key string) string

Query is a wrapper of r.URL.Query().Get()

func (*Context) SetHeader

func (c *Context) SetHeader(key string, value string)

SetHeader sets the header for response

func (*Context) Status

func (c *Context) Status(code int)

Status sets the status code for response

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{})

String sets the string for response

type Engine

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

Engine implement the interface of ServeHTTP

func Default

func Default() *Engine

Default use Logger() & Recovery middlewares

func New

func New() *Engine

New is the constructor of gsg.Engine

func (*Engine) LoadHTMLGlob

func (engine *Engine) LoadHTMLGlob(pattern string)

LoadHTMLGlob loads a html template

func (*Engine) Run

func (engine *Engine) Run(addr string) (err error)

Run defines the method to start a http server

func (*Engine) ServeHTTP

func (engine *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implement the interface of http.Handler

func (*Engine) SetFuncMap

func (engine *Engine) SetFuncMap(funcMap template.FuncMap)

SetFuncMap sets the funcMap for template

type H

type H map[string]interface{}

H is a shortcut for map[string]interface{}

type HandleFunc

type HandleFunc func(c *Context)

HandleFunc defines the request handler used by gsg

func Logger

func Logger() HandleFunc

func Recovery

func Recovery() HandleFunc

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

type RouterGroup

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

RouterGroup is a group of router

func (*RouterGroup) GET

func (group *RouterGroup) GET(relativePath string, handle HandleFunc)

GET defines the method to add GET request

func (*RouterGroup) Group

func (group *RouterGroup) Group(prefix string) *RouterGroup

Group is defined to create a new RouterGroup remember all groups share the same Engine instance

func (*RouterGroup) POST

func (group *RouterGroup) POST(relativePath string, handle HandleFunc)

POST defines the method to add POST request

func (*RouterGroup) Static

func (group *RouterGroup) Static(relativePath string, root string)

Static serve static files

func (*RouterGroup) Use

func (group *RouterGroup) Use(middlewares ...HandleFunc)

Jump to

Keyboard shortcuts

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