geek

package
v0.0.0-...-33dbcae Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
)

Variables

View Source
var (
	DefaultMiddlewares []ControllerHandler = []ControllerHandler{Recover(), TimeoutMonitor(100 * time.Second)}
)

Functions

func Dfs

func Dfs(n *Node)

Types

type Context

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

自定义Context 请求控制器 关于middleWares自己的一点感悟,相当于java的aop编程

func NewContext

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

func (*Context) BaseContext

func (ctx *Context) BaseContext() context.Context

func (*Context) BindJson

func (ctx *Context) BindJson(obj interface{}) error

封装响应 response

func (*Context) Deadline

func (ctx *Context) Deadline() (deadline time.Time, ok bool)

自定义的Context需要去实现context.Context context

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

func (*Context) Err

func (ctx *Context) Err() error

func (*Context) FormAll

func (ctx *Context) FormAll() map[string][]string

查询Post, 表单携带的数据 post

func (*Context) FormArray

func (ctx *Context) FormArray(key string, def []string) []string

func (*Context) FormInt

func (ctx *Context) FormInt(key string, def int) int

func (*Context) FormString

func (ctx *Context) FormString(key string, def string) string

func (*Context) GetRequest

func (ctx *Context) GetRequest() *http.Request

最基本的方法, 将封装的东西通过某种方法暴漏给外部使用,也叫base base

func (*Context) GetResponse

func (ctx *Context) GetResponse() http.ResponseWriter

func (*Context) HTML

func (ctx *Context) HTML(status int, obj interface{}, template string) error

func (*Context) HasTimeout

func (ctx *Context) HasTimeout() bool

func (*Context) Json

func (ctx *Context) Json(status int, obj interface{}) error

func (*Context) Next

func (ctx *Context) Next() error

func (*Context) QueryAll

func (ctx *Context) QueryAll() map[string][]string

通用查询方法 query

func (*Context) QueryArray

func (ctx *Context) QueryArray(key string, def []string) []string

func (*Context) QueryInt

func (ctx *Context) QueryInt(key string, def int) int

查询url,即url携带的数据 将常用的方法封装起来,便于调用,都是和req, res存取相关的方法

func (*Context) QueryString

func (ctx *Context) QueryString(key string, def string) string

func (*Context) SetHasTimeout

func (ctx *Context) SetHasTimeout()

func (*Context) Text

func (ctx *Context) Text(status int, obj string) error

func (*Context) Value

func (ctx *Context) Value(key interface{}) interface{}

type ControllerHandler

type ControllerHandler func(c *Context) error

自定义控制器

func Recover

func Recover() ControllerHandler

func TimeoutMonitor

func TimeoutMonitor(d time.Duration) ControllerHandler

type Engin

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

func NewDefaultEngin

func NewDefaultEngin() *Engin

func NewSimpleEngin

func NewSimpleEngin() *Engin

func (*Engin) Delete

func (engin *Engin) Delete(url string, handler ControllerHandler)

func (*Engin) FindHandlerByRequest

func (engin *Engin) FindHandlerByRequest(request *http.Request) []ControllerHandler

func (*Engin) Get

func (engin *Engin) Get(url string, handler ControllerHandler)

func (*Engin) Group

func (engin *Engin) Group(prefix string) IGroup

func (*Engin) Post

func (engin *Engin) Post(url string, handler ControllerHandler)

func (*Engin) Put

func (engin *Engin) Put(url string, handler ControllerHandler)

func (*Engin) Run

func (engin *Engin) Run(addr string) error

func (*Engin) ServeHTTP

func (engin *Engin) ServeHTTP(response http.ResponseWriter, request *http.Request)

func (*Engin) Use

func (engin *Engin) Use(middlewares ...ControllerHandler)

将公共的中间件给他注册进去

type Group

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

实现group接口

func NewGroup

func NewGroup(engin *Engin, prefix string) *Group

func (*Group) Delete

func (g *Group) Delete(uri string, handler ControllerHandler)

func (*Group) Get

func (g *Group) Get(uri string, handler ControllerHandler)

func (*Group) Post

func (g *Group) Post(uri string, handler ControllerHandler)

func (*Group) Put

func (g *Group) Put(uri string, handler ControllerHandler)

type IGroup

type IGroup interface {
	Get(string, ControllerHandler)
	Post(string, ControllerHandler)
	Put(string, ControllerHandler)
	Delete(string, ControllerHandler)
}

定义group接口 谈一些group的感想,一句话,group间接的去操作core.router目的就是注册路由,是一个非常巧妙的设计风格

type IRouter

type IRouter interface {
	RegisterRoute(information RouterInformation, middlewares []ControllerHandler) error
	FindHandlerByRouterInformation(information RouterInformation) []ControllerHandler
}

主要是存取方法

func NewSimpleRouter

func NewSimpleRouter() IRouter

工厂方法

type Node

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

func NewNode

func NewNode() *Node

type RouterInformation

type RouterInformation struct {
	Method string
	URL    string
}

定义一个路由接口,进一步实现解耦 面向接口设计而不是面向实现设计

type SimpleRouter

type SimpleRouter struct {
	Url2Handler map[string]map[string][]ControllerHandler
}

func (*SimpleRouter) FindHandlerByRouterInformation

func (r *SimpleRouter) FindHandlerByRouterInformation(information RouterInformation) []ControllerHandler

func (*SimpleRouter) RegisterRoute

func (r *SimpleRouter) RegisterRoute(information RouterInformation, middlewares []ControllerHandler) error

type StandardRouter

type StandardRouter struct {
	Url2Handler map[string]*Tree
}

func NewStandardRouter

func NewStandardRouter() *StandardRouter

func (*StandardRouter) FindHandlerByRouterInformation

func (s *StandardRouter) FindHandlerByRouterInformation(information RouterInformation) []ControllerHandler

func (*StandardRouter) RegisterRoute

func (s *StandardRouter) RegisterRoute(information RouterInformation, handlers []ControllerHandler) error

写的有问题, correct

type Tree

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

func NewTree

func NewTree() *Tree

func (*Tree) Root

func (tree *Tree) Root() *Node

Jump to

Keyboard shortcuts

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