neo

package
v0.0.0-...-06ac355 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTemplateOnEngine

func WithTemplateOnEngine(engine *Engine, opts ...TemplateOption)

Types

type Context

type Context struct {
	// 原始的请求和响应对象
	Writer http.ResponseWriter
	Req    *http.Request

	// 当此请求方式
	Method string
	// 当此请求地址
	URL string

	T TemplateEngine // 模板引擎实例
	// contains filtered or unexported fields
}

func NewContext

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

func (*Context) Abort

func (c *Context) Abort()

func (*Context) HTML

func (c *Context) HTML(code int, tplName string, data any)

HTML 返回HTML格式数据

func (*Context) JSON

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

JSON 返回JSON格式树 JSON格式数据特殊点,需要给它先序列化

func (*Context) Next

func (c *Context) Next()

Next 具体执行所有的视图函数

func (*Context) Params

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

Params 获取请求参数,请求参数这里需要使用到动态路由再获取

func (*Context) PostForm

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

PostForm 获取请求体数据 TODO 注意,根据用户传过来的数据格式的不同,获取数据的方式也是不同的。具体可以参考Gin

func (*Context) Query

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

Query 获取查询参数

func (*Context) SetHeader

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

SetHeader 设置响应头

func (*Context) Status

func (c *Context) Status(code int)

Status 设置响应状态码

func (*Context) String

func (c *Context) String(code int, template string, value ...string)

String 返回纯文本格式数据

type Engine

type Engine struct {
	*RouterGroup

	// 模板引擎对象
	T TemplateEngine
	// contains filtered or unexported fields
}

func Default

func Default() *Engine

Default use Logger() & Recovery middlewares

func New

func New() *Engine

func (*Engine) Run

func (e *Engine) Run(addr string) error

Run 手动启动服务,控制力强

func (*Engine) ServeHTTP

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

对外对接用户,对内对接Web框架

type GoTemplateEngine

type GoTemplateEngine struct {
	T *template.Template
}

func (*GoTemplateEngine) Render

func (g *GoTemplateEngine) Render(ctx context.Context, tplName string, data any) ([]byte, error)

Render 渲染数据

type H

type H map[string]string

type HandlerFunc

type HandlerFunc func(ctx *Context)

HandlerFunc 视图函数签名

func Recovery

func Recovery() HandlerFunc

type RouterGroup

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

func (*RouterGroup) DELETE

func (group *RouterGroup) DELETE(pattern string, handlerFunc HandlerFunc)

func (*RouterGroup) GET

func (group *RouterGroup) GET(pattern string, handlerFunc HandlerFunc)

GET 外部衍生API,提供给用户使用

func (*RouterGroup) Group

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

func (*RouterGroup) POST

func (group *RouterGroup) POST(pattern string, handlerFunc HandlerFunc)

func (*RouterGroup) PUT

func (group *RouterGroup) PUT(pattern string, handlerFunc HandlerFunc)

func (*RouterGroup) Use

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

type StaticFile

type StaticFile struct {
	Dir  string // 需要开放的文件路径
	Path string // 参数地址
}

func NewStaticFile

func NewStaticFile(dir string, path string) *StaticFile

func (*StaticFile) Handler

func (s *StaticFile) Handler() HandlerFunc

type TemplateEngine

type TemplateEngine interface {
	// Render 渲染页面方法
	// ctx 上下文,可能需要从中拿取相应树
	// tplName 模板名字
	// data 需要填充到模板中的数据
	// 返回值 []byte渲染后的模板数据
	// 返回值 error错误信息
	Render(ctx context.Context, tplName string, data any) ([]byte, error)
}

TemplateEngine 模板引擎抽象

func NewGoTemplateEngine

func NewGoTemplateEngine(t *template.Template) TemplateEngine

type TemplateOption

type TemplateOption func(engine *Engine)

因为模板引擎不是一个很常用的功能,所以我们这里做成一个可选的功能

Jump to

Keyboard shortcuts

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