gku

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: Apache-2.0 Imports: 33 Imported by: 0

README

gku

gku 是一个基于golang基础库封装的 web 框架,可用于开发 Web API和 Web 网站项目。

项目地址:

https://github.com/gkzy/gku

1. 快速开始:
mkdir hello
cd hello
go mod init
go get github.com/gkzy/gku
1.1 创建main.go
package main

import (
	"github.com/gkzy/gku"
)

func main() {
	r := gku.Default()
	r.AppName = "gku-demo"

	//输出json字串
	r.Get("/", func(c *gku.Context) {
		c.JSON("success")
	})

	//输出map
	r.Get("/hello", func(c *gku.Context) {
		c.JSON(gku.H{
			"code": 0,
			"msg":  "hello",
		})
	})

	//输出文本
	r.Get("/string", func(c *gku.Context) {
		c.String("success")
	})

	//default 8080
	//r.Run(9090)
	r.Run()
}


1.2 编译和运行
go build && ./hello

go run main.go
1.3 浏览器访问
http://127.0.0.1:8080
http://127.0.0.1:8080/hello
http://127.0.0.1:8080/string

Documentation

Index

Constants

View Source
const (
	DefaultProdConfig = "conf/prod.app.conf"
)

Variables

View Source
var (
	SupportMethods = []string{
		"GET",
		"POST",
		"HEAD",
		"DELETE",
		"PUT",
		"OPTIONS",
		"TRACE",
		"PATCH",
	}

	PoolSize = 10
)

Functions

func InitSession

func InitSession()

InitSession init gku session

before using session,please call this function first

func NewCookie

func NewCookie(name string, value string, age ...int64) *http.Cookie

NewCookie return a http.Cookie via give name and value

func NewSecureCookie

func NewSecureCookie(secret, name string, val string, age ...int64) *http.Cookie

NewSecureCookie generates a new secure cookie

Types

type AbortError

type AbortError interface {
	error
	Code() int
}

AbortError defines an interface to describe HTTP error

func Abort

func Abort(code int, content ...string) AbortError

Abort returns an AbortError

func Forbidden

func Forbidden(content ...string) AbortError

Forbidden returns forbidden HTTP error

func InternalServerError

func InternalServerError(content ...string) AbortError

InternalServerError returns internal server HTTP error

func NotFound

func NotFound(content ...string) AbortError

NotFound returns not found HTTP error

func NotSupported

func NotSupported(content ...string) AbortError

NotSupported returns not supported HTTP error

func Unauthorized

func Unauthorized(content ...string) AbortError

Unauthorized returns unauthorized HTTP error

type AppConfig

type AppConfig struct {
	AppName       string //应用名称
	RunMode       string //运行模板
	HttpAddr      string //监听端口
	AutoRender    bool   //是否自动渲染html模板
	Views         string //html模板目录
	TemplateLeft  string //模板符号
	TemplateRight string //模板符号
	SessionOn     bool   //是否打开session
}

AppConfig gku app 统一配置入口

可以通过AppConfig完成统一的app基础配置

func GetAppConfig

func GetAppConfig() *AppConfig

GetAppConfig 获取配置文件中的信息

默认使用conf/app.conf配置文件
当环境变量 APP_RUN_MODE ="prod"时,使用 conf/prod.app.conf
当环境变量 APP_RUN_MODE ="dev"时,使用 conf/dev.app.conf
没有此环境变量时,使用conf/app.conf

type Body

type Body struct {
	Pager *Pager      `json:"pager"`
	Data  interface{} `json:"data"`
}

type Context

type Context struct {
	ResponseWriter

	//Data html template data msp
	Data map[interface{}]interface{}

	Result interface{}

	Pager *Pager
	// contains filtered or unexported fields
}

Context gku context

func (*Context) Abort

func (c *Context) Abort(status int, body ...string)

Abort

func (*Context) Action

func (c *Context) Action() interface{}

Action returns action

func (*Context) ActionTag

func (c *Context) ActionTag(fieldName string) string

ActionTag returns field tag on action struct TODO: cache the name

func (*Context) ActionValue

func (c *Context) ActionValue() reflect.Value

ActionValue returns action value

func (*Context) Body

func (c *Context) Body() []byte

RequestBody RequestBody

func (*Context) Cookie

func (c *Context) Cookie(key string, defaults ...string) string

Cookie returns cookie as string with default

func (*Context) CookieBool

func (c *Context) CookieBool(key string, defaults ...bool) bool

CookieBool returns cookie as bool with default

func (*Context) CookieEscape

func (c *Context) CookieEscape(key string, defaults ...string) string

CookieEscape returns cookie as escaped string with default

func (*Context) CookieFloat32

func (c *Context) CookieFloat32(key string, defaults ...float32) float32

CookieFloat32 returns cookie as float32 with default

func (*Context) CookieFloat64

func (c *Context) CookieFloat64(key string, defaults ...float64) float64

CookieFloat64 returns cookie as float64 with default

func (*Context) CookieInt

func (c *Context) CookieInt(key string, defaults ...int) int

CookieInt returns cookie as int with default

func (*Context) CookieInt32

func (c *Context) CookieInt32(key string, defaults ...int32) int32

CookieInt32 returns cookie as int32 with default

func (*Context) CookieInt64

func (c *Context) CookieInt64(key string, defaults ...int64) int64

CookieInt64 returns cookie as int64 with default

func (*Context) CookieUint

func (c *Context) CookieUint(key string, defaults ...uint) uint

CookieUint returns cookie as uint with default

func (*Context) CookieUint32

func (c *Context) CookieUint32(key string, defaults ...uint32) uint32

CookieUint32 returns cookie as uint32 with default

func (*Context) CookieUint64

func (c *Context) CookieUint64(key string, defaults ...uint64) uint64

CookieUint64 returns cookie as uint64 with default

func (*Context) Cookies

func (c *Context) Cookies() Cookies

Cookies returns the cookies

func (*Context) DataJSON

func (c *Context) DataJSON(args ...interface{})

DataJSON DataJSON json data

response format json

func (*Context) DecodeJSONBody

func (c *Context) DecodeJSONBody(v interface{}) error

DecodeJSON

func (*Context) DeleteSession

func (c *Context) DeleteSession(key string)

DeleteSession delete session key

func (*Context) Download

func (c *Context) Download(data []byte)

Download

func (*Context) File

func (c *Context) File(filePath string)

File read file to http body stream

func (*Context) Form

func (c *Context) Form(key string, defaults ...string) string

Form returns request form as string with default

func (*Context) FormBool

func (c *Context) FormBool(key string, defaults ...bool) bool

FormBool returns request form as bool with default

func (*Context) FormEscape

func (c *Context) FormEscape(key string, defaults ...string) string

FormEscape returns request form as escaped string with default

func (*Context) FormFloat32

func (c *Context) FormFloat32(key string, defaults ...float32) float32

FormFloat32 returns request form as float32 with default

func (*Context) FormFloat64

func (c *Context) FormFloat64(key string, defaults ...float64) float64

FormFloat64 returns request form as float64 with default

func (*Context) FormInt

func (c *Context) FormInt(key string, defaults ...int) int

FormInt returns request form as int with default

func (*Context) FormInt32

func (c *Context) FormInt32(key string, defaults ...int32) int32

FormInt32 returns request form as int32 with default

func (*Context) FormInt64

func (c *Context) FormInt64(key string, defaults ...int64) int64

FormInt64 returns request form as int64 with default

func (*Context) FormStrings

func (c *Context) FormStrings(key string, defaults ...[]string) []string

FormStrings returns request form as strings with default

func (*Context) FormTrimmed

func (c *Context) FormTrimmed(key string, defaults ...string) string

FormTrimmed returns request form as string with default and trimmed spaces

func (*Context) FormUint

func (c *Context) FormUint(key string, defaults ...uint) uint

FormUint returns request form as uint with default

func (*Context) FormUint32

func (c *Context) FormUint32(key string, defaults ...uint32) uint32

FormUint32 returns request form as uint32 with default

func (*Context) FormUint64

func (c *Context) FormUint64(key string, defaults ...uint64) uint64

FormUint64 returns request form as uint64 with default

func (*Context) Forms

func (c *Context) Forms() *Forms

Forms return the query/body names and values

func (*Context) GetFile

func (c *Context) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

GetFile get single from

func (*Context) GetFiles

func (c *Context) GetFiles(key string) ([]*multipart.FileHeader, error)

GetFiles GetFiles

func (*Context) GetHeader

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

GetHeader get http request header value by key

func (*Context) GetSession

func (c *Context) GetSession(key string) interface{}

GetSession return interface

func (*Context) HTML

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

HTML render html page

When inputting data, use the value of data, otherwise use c.Data

func (*Context) HandleError

func (c *Context) HandleError()

func (*Context) Host

func (c *Context) Host() string

Host request host

func (*Context) IP

func (c *Context) IP() (ip string)

IP return ip address

func (*Context) IsAjax

func (c *Context) IsAjax() bool

IsAjax return is ajax request

func (*Context) IsWeChat

func (c *Context) IsWeChat() bool

IsWeChat return is WeChat user-agent

func (*Context) IsWebsocket

func (c *Context) IsWebsocket() bool

IsWebsocket return is websocket request

func (*Context) JSON

func (c *Context) JSON(data interface{})

JSON response json doc

func (*Context) Next

func (c *Context) Next()

func (*Context) NotFound

func (c *Context) NotFound(msg ...string)

NotFound writes a 404 HTTP response

func (*Context) Param

func (c *Context) Param(key string, defaults ...string) string

Param returns request form as string with default

func (*Context) ParamBool

func (c *Context) ParamBool(key string, defaults ...bool) bool

ParamBool returns request form as bool with default

func (*Context) ParamEscape

func (c *Context) ParamEscape(key string, defaults ...string) string

ParamEscape returns request form as escaped string with default

func (*Context) ParamFloat32

func (c *Context) ParamFloat32(key string, defaults ...float32) float32

ParamFloat32 returns request form as float32 with default

func (*Context) ParamFloat64

func (c *Context) ParamFloat64(key string, defaults ...float64) float64

ParamFloat64 returns request form as float64 with default

func (*Context) ParamInt

func (c *Context) ParamInt(key string, defaults ...int) int

ParamInt returns request form as int with default

func (*Context) ParamInt32

func (c *Context) ParamInt32(key string, defaults ...int32) int32

ParamInt32 returns request form as int32 with default

func (*Context) ParamInt64

func (c *Context) ParamInt64(key string, defaults ...int64) int64

ParamInt64 returns request form as int64 with default

func (*Context) ParamStrings

func (c *Context) ParamStrings(key string, defaults ...[]string) []string

ParamStrings returns request form as slice of string with default

func (*Context) ParamUint

func (c *Context) ParamUint(key string, defaults ...uint) uint

ParamUint returns request form as uint with default

func (*Context) ParamUint32

func (c *Context) ParamUint32(key string, defaults ...uint32) uint32

ParamUint32 returns request form as uint32 with default

func (*Context) ParamUint64

func (c *Context) ParamUint64(key string, defaults ...uint64) uint64

ParamUint64 returns request form as uint64 with default

func (*Context) Params

func (c *Context) Params() *Params

Params returns the URL params

func (*Context) Queries

func (c *Context) Queries() *Queries

Queries return the query names and values

func (*Context) Query

func (c *Context) Query(key string, defaults ...string) string

Query returns request form as string with default

func (*Context) QueryBool

func (c *Context) QueryBool(key string, defaults ...bool) bool

FormBool returns request form as bool with default

func (*Context) QueryEscape

func (c *Context) QueryEscape(key string, defaults ...string) string

QueryEscape returns request form as escaped string with default

func (*Context) QueryFloat32

func (c *Context) QueryFloat32(key string, defaults ...float32) float32

QueryFloat32 returns request form as float32 with default

func (*Context) QueryFloat64

func (c *Context) QueryFloat64(key string, defaults ...float64) float64

FormFloat64 returns request form as float64 with default

func (*Context) QueryInt

func (c *Context) QueryInt(key string, defaults ...int) int

QueryInt returns request form as int with default

func (*Context) QueryInt32

func (c *Context) QueryInt32(key string, defaults ...int32) int32

QueryInt32 returns request form as int32 with default

func (*Context) QueryInt64

func (c *Context) QueryInt64(key string, defaults ...int64) int64

QueryInt64 returns request form as int64 with default

func (*Context) QueryStrings

func (c *Context) QueryStrings(key string, defaults ...[]string) []string

QueryStrings returns request form as strings with default

func (*Context) QueryUint

func (c *Context) QueryUint(key string, defaults ...uint) uint

QueryUint returns request form as uint with default

func (*Context) QueryUint32

func (c *Context) QueryUint32(key string, defaults ...uint32) uint32

QueryUint32 returns request form as uint32 with default

func (*Context) QueryUint64

func (c *Context) QueryUint64(key string, defaults ...uint64) uint64

QueryUint64 returns request form as uint64 with default

func (*Context) Redirect

func (c *Context) Redirect(url string, status ...int)

Redirect redirect the request to another URL

Redirect("/login",302)
Redirect("http://zituo.net",301)

func (*Context) Referer

func (c *Context) Referer() string

Referer Referer

func (*Context) Render

func (c *Context) Render(statusCode int, r render.Render)

Render render interface

func (*Context) Req

func (c *Context) Req() *http.Request

func (*Context) Route

func (c *Context) Route() *Route

Route returns route

func (*Context) SaveToFile

func (c *Context) SaveToFile(fromFile, toFile string) error

SaveToFile saves uploaded file to new path.

upload the file and save it on the server
c.SaveToFile("file","./upload/1.jpg")

func (*Context) ServerHTML

func (c *Context) ServerHTML(statusCode int, name string, data ...interface{})

ServerHTML

When inputting data, use the value of data, otherwise use c.Data

func (*Context) ServerJSON

func (c *Context) ServerJSON(statusCode int, data interface{})

ServerJSON

func (*Context) ServerString

func (c *Context) ServerString(statusCode int, msg string)

ServerString ServerString

func (*Context) ServerXML

func (c *Context) ServerXML(statusCode int, data interface{})

ServerXML

func (*Context) SessionBool

func (c *Context) SessionBool(key string) bool

SessionBool return bool

default false

func (*Context) SessionInt

func (c *Context) SessionInt(key string) int

SessionInt return int

default 0

func (*Context) SessionInt64

func (c *Context) SessionInt64(key string) int64

SessionInt64 return int64

default 0

func (*Context) SessionString

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

SessionString return string

func (*Context) SetCookie

func (c *Context) SetCookie(key, value string, maxAge int, path, domain string, secure, httpOnly bool)

SetCookie set cookie

c.SetCookie("username", "gku", 72*time.Hour, "", true, true)

func (*Context) SetHeader

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

SetHeader set http response header

func (*Context) SetRequest

func (c *Context) SetRequest(r *http.Request)

func (*Context) SetSession

func (c *Context) SetSession(key string, v interface{})

SetSession set session

func (*Context) String

func (c *Context) String(msg string)

String response string doc

func (*Context) UserAgent

func (c *Context) UserAgent() string

UserAgent request useragent

func (*Context) XML

func (c *Context) XML(data interface{})

XML response xml doc

type Contexter

type Contexter interface {
	SetContext(*Context)
}

Contexter

type Controller

type Controller struct {
	*Context
}

Controller implements Contexter

func (*Controller) SetContext

func (c *Controller) SetContext(ctx *Context)

SetContext set *Context to action struct

type Cookies

type Cookies interface {
	Set
	Get(string) *http.Cookie
	Set(*http.Cookie)
	Expire(string, time.Time)
	Del(string)
}

Cookies describes cookie interface

type DataResponse

type DataResponse struct {
	Code  int    `json:"code"`
	Msg   string `json:"msg"`
	STime string `json:"stime"`
	Time  int    `json:"time"`
	Body  *Body  `json:"body"`
}

DataResponse data json response struct

type Engine

type Engine struct {
	AppName string
	RunMode string
	AppPath string

	http.Server
	RouterInterface

	ErrHandler Handler

	//template
	FuncMap    template.FuncMap
	AutoRender bool
	HTMLRender render.Render

	MaxMultipartMemory int64
	// contains filtered or unexported fields
}

Engine gku engine

func Default

func Default(handlers ...Handler) *Engine

Default return a default Engine

func New

func New(handlers ...Handler) *Engine

New return a new Engine

func (*Engine) AddFuncMap

func (engine *Engine) AddFuncMap(key string, fn interface{})

AddFuncMap add template func map

添加自定义的模板函数

func (*Engine) Any

func (engine *Engine) Any(p string, c interface{}, middlewares ...Handler)

Any

func (*Engine) Delete

func (engine *Engine) Delete(p string, c interface{}, middlewares ...Handler)

Delete sets a route with DELETE method

func (*Engine) Get

func (engine *Engine) Get(p string, c interface{}, middlewares ...Handler)

Get sets a route with GET method

func (*Engine) Group

func (engine *Engine) Group(p string, o interface{}, handlers ...Handler)

Group adds routines groups

func (*Engine) Head

func (engine *Engine) Head(p string, c interface{}, middlewares ...Handler)

Head sets a route with HEAD method

func (*Engine) NotFoundHandler

func (engine *Engine) NotFoundHandler(handler Handler)

NotFoundHandler custom page not found

func (*Engine) Options

func (engine *Engine) Options(p string, c interface{}, middlewares ...Handler)

Options sets a route with OPTIONS method

func (*Engine) Patch

func (engine *Engine) Patch(p string, c interface{}, middlewares ...Handler)

Patch sets a route with PATCH method

func (*Engine) Post

func (engine *Engine) Post(p string, c interface{}, middlewares ...Handler)

Post sets a route with POST method

func (*Engine) Put

func (engine *Engine) Put(p string, c interface{}, middlewares ...Handler)

Put sets a route with PUT method

func (*Engine) Run

func (engine *Engine) Run(args ...interface{}) (err error)

Run start a http server.Listening on os.GetEnv("PORT") or 8080 by default

func (*Engine) RunTLS

func (engine *Engine) RunTLS(certFile, keyFile string, args ...interface{}) (err error)

RunTLS

func (*Engine) ServeHTTP

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

ServeHTTP ServeHTTP

func (*Engine) SetAppConfig

func (engine *Engine) SetAppConfig(app *AppConfig)

SetAppConfig 统一配置入口

可使用此方法统一配置,也可以使用其他方法单独设置

func (*Engine) SetDelims

func (engine *Engine) SetDelims(left, right string)

SetDelims set delims

default left:{{ right:}}

func (*Engine) SetSessionOn

func (engine *Engine) SetSessionOn(on bool)

SetSessionOn 打开session

func (*Engine) SetView

func (engine *Engine) SetView(path ...string)

SetView set views path

模板目录为views时,可以不调用此方法

func (*Engine) Static

func (engine *Engine) Static(relativePath, root string)

Static Static

func (*Engine) Trace

func (engine *Engine) Trace(p string, c interface{}, middlewares ...Handler)

Trace sets a route with TRACE method

func (*Engine) Use

func (engine *Engine) Use(handlers ...Handler)

Use Use

func (*Engine) UseHandler

func (engine *Engine) UseHandler(handler http.Handler)

UseHandler adds a standard http handler to engine's

type ErrorKeyIsNotExist

type ErrorKeyIsNotExist struct {
	Key string
}

func (ErrorKeyIsNotExist) Error

func (e ErrorKeyIsNotExist) Error() string

type ErrorWithCode

type ErrorWithCode interface {
	error
	ErrorCode() int
}

ErrorWithCode descripts an error that with error code

type Forms

type Forms http.Request

Forms a new enhancement of http.Request

func (*Forms) Bool

func (f *Forms) Bool(key string) (bool, error)

Bool returns request form as bool

func (*Forms) Escape

func (f *Forms) Escape(key string) (string, error)

Escape returns request form as escaped string

func (*Forms) Float32

func (f *Forms) Float32(key string) (float32, error)

Float32 returns request form as float32

func (*Forms) Float64

func (f *Forms) Float64(key string) (float64, error)

Float64 returns request form as float64

func (*Forms) Int

func (f *Forms) Int(key string) (int, error)

Int returns request form as int

func (*Forms) Int32

func (f *Forms) Int32(key string) (int32, error)

Int32 returns request form as int32

func (*Forms) Int64

func (f *Forms) Int64(key string) (int64, error)

Int64 returns request form as int64

func (*Forms) MustBool

func (f *Forms) MustBool(key string, defaults ...bool) bool

MustBool returns request form as bool with default

func (*Forms) MustEscape

func (f *Forms) MustEscape(key string, defaults ...string) string

MustEscape returns request form as escaped string with default

func (*Forms) MustFloat32

func (f *Forms) MustFloat32(key string, defaults ...float32) float32

MustFloat32 returns request form as float32 with default

func (*Forms) MustFloat64

func (f *Forms) MustFloat64(key string, defaults ...float64) float64

MustFloat64 returns request form as float64 with default

func (*Forms) MustInt

func (f *Forms) MustInt(key string, defaults ...int) int

MustInt returns request form as int with default

func (*Forms) MustInt32

func (f *Forms) MustInt32(key string, defaults ...int32) int32

MustInt32 returns request form as int32 with default

func (*Forms) MustInt64

func (f *Forms) MustInt64(key string, defaults ...int64) int64

MustInt64 returns request form as int64 with default

func (*Forms) MustString

func (f *Forms) MustString(key string, defaults ...string) string

MustString returns request form as string with default

func (*Forms) MustStrings

func (f *Forms) MustStrings(key string, defaults ...[]string) []string

MustStrings returns request form as strings with default

func (*Forms) MustTrimmed

func (f *Forms) MustTrimmed(key string, defaults ...string) string

MustTrimmed returns request form as string with default

func (*Forms) MustUint

func (f *Forms) MustUint(key string, defaults ...uint) uint

MustUint returns request form as uint with default

func (*Forms) MustUint32

func (f *Forms) MustUint32(key string, defaults ...uint32) uint32

MustUint32 returns request form as uint32 with default

func (*Forms) MustUint64

func (f *Forms) MustUint64(key string, defaults ...uint64) uint64

MustUint64 returns request form as uint64 with default

func (*Forms) String

func (f *Forms) String(key string) (string, error)

String returns request form as string

func (*Forms) Strings

func (f *Forms) Strings(key string) ([]string, error)

Strings returns request form as strings

func (*Forms) Trimmed

func (f *Forms) Trimmed(key string) (string, error)

TrimSpace returns request form as string with trimed spaces left and right

func (*Forms) Uint

func (f *Forms) Uint(key string) (uint, error)

Uint returns request form as uint

func (*Forms) Uint32

func (f *Forms) Uint32(key string) (uint32, error)

Uint32 returns request form as uint32

func (*Forms) Uint64

func (f *Forms) Uint64(key string) (uint64, error)

Uint64 returns request form as uint64

func (*Forms) Values

func (f *Forms) Values() url.Values

Values returns http.Request values

type Group

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

Group defines a route group

func NewGroup

func NewGroup() *Group

NewGroup creates a route group

func (*Group) Any

func (g *Group) Any(p string, c interface{}, middlewares ...Handler)

Any add the default mehtods route to this group

func (*Group) Delete

func (g *Group) Delete(p string, c interface{}, middlewares ...Handler)

Delete add a DELETE route to this group

func (*Group) Get

func (g *Group) Get(p string, c interface{}, middlewares ...Handler)

Get add a GET route to this group

func (*Group) Group

func (g *Group) Group(p string, o interface{}, handlers ...Handler)

Group defines group's child group

func (*Group) Handle

func (g *Group) Handle(method, p string, c interface{}, middlewares ...Handler)

Route defines a customerize route to this group

func (*Group) Head

func (g *Group) Head(url, p string, c interface{}, middlewares ...Handler)

Head add a HEAD route to this group

func (*Group) Options

func (g *Group) Options(p string, c interface{}, middlewares ...Handler)

Options add a OPTIONS route to this group

func (*Group) Patch

func (g *Group) Patch(p string, c interface{}, middlewares ...Handler)

Patch add a PATCH route to this group

func (*Group) Post

func (g *Group) Post(p string, c interface{}, middlewares ...Handler)

Post add a POST route to this group

func (*Group) Put

func (g *Group) Put(p string, c interface{}, middlewares ...Handler)

Put add a PUT route to this group

func (*Group) Trace

func (g *Group) Trace(p string, c interface{}, middlewares ...Handler)

Trace add a TRACE route to this group

func (*Group) Use

func (g *Group) Use(handlers ...Handler)

Use set the middlewares to apply to this group's routes

type H

type H map[string]interface{}

H map

gku.H

type Handler

type Handler interface {
	Handle(*Context)
}

type HandlerFunc

type HandlerFunc func(c *Context)

func Contexts

func Contexts() HandlerFunc

Contexts returns a middleware to inject Context to action struct

func DataPager

func DataPager() HandlerFunc

DataPager middlewares

实现分页参数的处理

func Errors

func Errors() HandlerFunc

Errors returns default error handler, you can use your self handler

func Logger

func Logger() HandlerFunc

func Param

func Param() HandlerFunc

Param returns params handle to operate param

func Recovery

func Recovery() HandlerFunc

func Return

func Return() HandlerFunc

Return returns a tango middleware to handler return values

func Session

func Session() HandlerFunc

Session session middleware

r := gku.Default()
r.Use(gku.Session())

func Static

func Static(opts ...StaticOptions) HandlerFunc

Static

func WrapAfter

func WrapAfter(handler http.Handler) HandlerFunc

WrapAfter wraps a http standard handler to tango's after action executes

func WrapBefore

func WrapBefore(handler http.Handler) HandlerFunc

WrapBefore wraps a http standard handler to gku's before action executes

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(c *Context)

type JSON

type JSON struct{}

JSON describes return JSON type

func (JSON) ResponseType

func (JSON) ResponseType() int

ResponseType implementes ResponseTyper

type Json

type Json struct{}

Json describes return JSON type Deprecated: use JSON instead

func (Json) ResponseType

func (Json) ResponseType() int

ResponseType implementes ResponseTyper

type Pager

type Pager struct {
	Page      int64 `json:"page"`
	Limit     int64 `json:"limit"`
	Offset    int64 `json:"offset"`
	Count     int64 `json:"count"`
	PageCount int64 `json:"page_count"`
}

Pager

type Paramer

type Paramer interface {
	SetParams([]param)
}

Paramer defines an interface to get params

type Params

type Params []param

Params defines params of http request

func (*Params) Bool

func (p *Params) Bool(key string) (bool, error)

Bool returns request form as bool

func (*Params) Escape

func (p *Params) Escape(key string) (string, error)

Escape returns request form as escaped string

func (*Params) Float32

func (p *Params) Float32(key string) (float32, error)

Float32 returns request form as float32

func (*Params) Float64

func (p *Params) Float64(key string) (float64, error)

Float64 returns request form as float64

func (*Params) Get

func (p *Params) Get(key string) string

Get returns request form as string

func (*Params) Int

func (p *Params) Int(key string) (int, error)

Int returns request form as int

func (*Params) Int32

func (p *Params) Int32(key string) (int32, error)

Int32 returns request form as int32

func (*Params) Int64

func (p *Params) Int64(key string) (int64, error)

Int64 returns request form as int64

func (*Params) MustBool

func (p *Params) MustBool(key string, defaults ...bool) bool

MustBool returns request form as bool with default

func (*Params) MustEscape

func (p *Params) MustEscape(key string, defaults ...string) string

MustEscape returns request form as escaped string with default

func (*Params) MustFloat32

func (p *Params) MustFloat32(key string, defaults ...float32) float32

MustFloat32 returns request form as float32 with default

func (*Params) MustFloat64

func (p *Params) MustFloat64(key string, defaults ...float64) float64

MustFloat64 returns request form as float64 with default

func (*Params) MustInt

func (p *Params) MustInt(key string, defaults ...int) int

MustInt returns request form as int with default

func (*Params) MustInt32

func (p *Params) MustInt32(key string, defaults ...int32) int32

MustInt32 returns request form as int32 with default

func (*Params) MustInt64

func (p *Params) MustInt64(key string, defaults ...int64) int64

MustInt64 returns request form as int64 with default

func (*Params) MustString

func (p *Params) MustString(key string, defaults ...string) string

MustString returns request form as slice of string with default

func (*Params) MustStrings

func (p *Params) MustStrings(key string, defaults ...[]string) []string

MustStrings returns request form as slice of string with default

func (*Params) MustUint

func (p *Params) MustUint(key string, defaults ...uint) uint

MustUint returns request form as uint with default

func (*Params) MustUint32

func (p *Params) MustUint32(key string, defaults ...uint32) uint32

MustUint32 returns request form as uint32 with default

func (*Params) MustUint64

func (p *Params) MustUint64(key string, defaults ...uint64) uint64

MustUint64 returns request form as uint64 with default

func (*Params) Set

func (p *Params) Set(key, value string)

Set sets key/value to params

func (*Params) SetParams

func (p *Params) SetParams(params []param)

SetParams implemented Paramer

func (*Params) String

func (p *Params) String(key string) (string, error)

String returns request form as string

func (*Params) Strings

func (p *Params) Strings(key string) ([]string, error)

Strings returns request form as slice of string

func (*Params) Uint

func (p *Params) Uint(key string) (uint, error)

Uint returns request form as uint

func (*Params) Uint32

func (p *Params) Uint32(key string) (uint32, error)

Uint32 returns request form as uint32

func (*Params) Uint64

func (p *Params) Uint64(key string) (uint64, error)

Uint64 returns request form as uint64

type Queries

type Queries http.Request

Queries a new enhancement of http.Request

func (*Queries) Bool

func (f *Queries) Bool(key string) (bool, error)

Bool returns request form as bool

func (*Queries) Escape

func (f *Queries) Escape(key string) (string, error)

Escape returns request form as escaped string

func (*Queries) Float32

func (f *Queries) Float32(key string) (float32, error)

Float32 returns request form as float32

func (*Queries) Float64

func (f *Queries) Float64(key string) (float64, error)

Float64 returns request form as float64

func (*Queries) Int

func (f *Queries) Int(key string) (int, error)

Int returns request form as int

func (*Queries) Int32

func (f *Queries) Int32(key string) (int32, error)

Int32 returns request form as int32

func (*Queries) Int64

func (f *Queries) Int64(key string) (int64, error)

Int64 returns request form as int64

func (*Queries) MustBool

func (f *Queries) MustBool(key string, defaults ...bool) bool

MustBool returns request form as bool with default

func (*Queries) MustEscape

func (f *Queries) MustEscape(key string, defaults ...string) string

MustEscape returns request form as escaped string with default

func (*Queries) MustFloat32

func (f *Queries) MustFloat32(key string, defaults ...float32) float32

MustFloat32 returns request form as float32 with default

func (*Queries) MustFloat64

func (f *Queries) MustFloat64(key string, defaults ...float64) float64

MustFloat64 returns request form as float64 with default

func (*Queries) MustInt

func (f *Queries) MustInt(key string, defaults ...int) int

MustInt returns request form as int with default

func (*Queries) MustInt32

func (f *Queries) MustInt32(key string, defaults ...int32) int32

MustInt32 returns request form as int32 with default

func (*Queries) MustInt64

func (f *Queries) MustInt64(key string, defaults ...int64) int64

MustInt64 returns request form as int64 with default

func (*Queries) MustString

func (f *Queries) MustString(key string, defaults ...string) string

MustString returns request form as string with default

func (*Queries) MustStrings

func (f *Queries) MustStrings(key string, defaults ...[]string) []string

MustStrings returns request form as strings with default

func (*Queries) MustUint

func (f *Queries) MustUint(key string, defaults ...uint) uint

MustUint returns request form as uint with default

func (*Queries) MustUint32

func (f *Queries) MustUint32(key string, defaults ...uint32) uint32

MustUint32 returns request form as uint32 with default

func (*Queries) MustUint64

func (f *Queries) MustUint64(key string, defaults ...uint64) uint64

MustUint64 returns request form as uint64 with default

func (*Queries) String

func (f *Queries) String(key string) (string, error)

String returns request form as string

func (*Queries) Strings

func (f *Queries) Strings(key string) ([]string, error)

Strings returns request form as strings

func (*Queries) Uint

func (f *Queries) Uint(key string) (uint, error)

Uint returns request form as uint

func (*Queries) Uint32

func (f *Queries) Uint32(key string) (uint32, error)

Uint32 returns request form as uint32

func (*Queries) Uint64

func (f *Queries) Uint64(key string) (uint64, error)

Uint64 returns request form as uint64

func (*Queries) Values

func (f *Queries) Values() url.Values

Values returns http.Request values

type ResponseTyper

type ResponseTyper interface {
	ResponseType() int
}

ResponseTyper describes reponse type

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	http.Hijacker

	Status() int
	Written() bool
	Size() int
}

ResponseWriter http response interface

type Route

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

Route HTTP route

func NewRoute

func NewRoute(v interface{}, t reflect.Type, method reflect.Value, tp RouteType, handlers []Handler) *Route

NewRoute return a route

func (*Route) IsStruct

func (r *Route) IsStruct() bool

IsStruct returns if the execute is a struct

func (*Route) Method

func (r *Route) Method() reflect.Value

Method returns finalize execute method.

func (*Route) Raw

func (r *Route) Raw() interface{}

func (*Route) RouteType

func (r *Route) RouteType() RouteType

RouteType returns route type.

type RouteType

type RouteType byte
const (
	FuncRoute         RouteType = iota + 1 // 1 func ()
	FuncHTTPRoute                          // 2 func (http.ResponseWriter, *http.Request)
	FuncReqRoute                           // 3 func (*http.Request)
	FuncResponseRoute                      // 4 func (http.ResponseWriter)
	FuncCtxRoute                           // 5 func (*tango.Context)
	StructRoute                            // 6 func (st) <Get>()
	StructPtrRoute                         // 7 func (*struct) <Get>()
)

type RouterInterface

type RouterInterface interface {
	Handle(method, p string, handler interface{}, middlewares ...Handler)
	Match(requestPath, method string) (*Route, Params)
	Router(p string, c interface{}, mappingMethods ...string)
}

RouterInterface router interface

type Set

type Set interface {
	String(key string) (string, error)
	Int(key string) (int, error)
	Int32(key string) (int32, error)
	Int64(key string) (int64, error)
	Uint(key string) (uint, error)
	Uint32(key string) (uint32, error)
	Uint64(key string) (uint64, error)
	Float32(key string) (float32, error)
	Float64(key string) (float64, error)
	Bool(key string) (bool, error)

	MustString(key string, defaults ...string) string
	MustEscape(key string, defaults ...string) string
	MustInt(key string, defaults ...int) int
	MustInt32(key string, defaults ...int32) int32
	MustInt64(key string, defaults ...int64) int64
	MustUint(key string, defaults ...uint) uint
	MustUint32(key string, defaults ...uint32) uint32
	MustUint64(key string, defaults ...uint64) uint64
	MustFloat32(key string, defaults ...float32) float32
	MustFloat64(key string, defaults ...float64) float64
	MustBool(key string, defaults ...bool) bool
}

type StaticOptions

type StaticOptions struct {
	RootPath   string
	Prefix     string
	IndexFiles []string
	ListDir    bool
	FilterExts []string
	FileSystem http.FileSystem
}

StaticOptions 静态文件选项

func (*StaticOptions) IsFilterExt

func (s *StaticOptions) IsFilterExt(p string) bool

IsFilterExt 过滤文件

type StatusResult

type StatusResult struct {
	Code   int
	Result interface{}
}

StatusResult describes http response

type XML

type XML struct{}

XML descirbes return XML type

func (XML) ResponseType

func (XML) ResponseType() int

ResponseType implementes ResponseTyper

type XMLError

type XMLError struct {
	XMLName xml.Name `xml:"err"`
	Content string   `xml:"content"`
}

XMLError describes return xml error

type XMLString

type XMLString struct {
	XMLName xml.Name `xml:"string"`
	Content string   `xml:"content"`
}

XMLString describes return xml string

type Xml

type Xml struct{}

Xml descirbes return XML type Deprecated: use XML instead

func (Xml) ResponseType

func (Xml) ResponseType() int

ResponseType implementes ResponseTyper

Directories

Path Synopsis
lib
logy
like https://gitea.com/lunny/log but made some adjustments
like https://gitea.com/lunny/log but made some adjustments
nsq
//init pu,err:=NewProducer("192.168.0.197",4150) if err!=nil{ //error } b,_:=json.Marshal(obj) //发送 err = pu.Publish("topic",b) if err!=nil{ //error }
//init pu,err:=NewProducer("192.168.0.197",4150) if err!=nil{ //error } b,_:=json.Marshal(obj) //发送 err = pu.Publish("topic",b) if err!=nil{ //error }
oauth/wechat
微信第三方登录相关 公众号支付相关 全局token相关 client:=NewClient(appId,secret) client.SetApiKey("支付的apiKey") ....
微信第三方登录相关 公众号支付相关 全局token相关 client:=NewClient(appId,secret) client.SetApiKey("支付的apiKey") ....
oss
pay/wepay
基础通讯业务实现 sam
基础通讯业务实现 sam
redis
使用方法: 1.
使用方法: 1.
rpc
sms
util
AES CBC PKCS5Padding加/解密 使用 hex.Encode 查看测试文件: aes_cbc_test.go http client 使用github.com/imroc/req库 返回string,如果需要到struct,需要自己反序列化
AES CBC PKCS5Padding加/解密 使用 hex.Encode 查看测试文件: aes_cbc_test.go http client 使用github.com/imroc/req库 返回string,如果需要到struct,需要自己反序列化
from beego template link: github.com/astaxie/beego/fs.go from beego template link: github.com/astaxie/beego/template.go
from beego template link: github.com/astaxie/beego/fs.go from beego template link: github.com/astaxie/beego/template.go

Jump to

Keyboard shortcuts

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