ecgo

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

README

ecgo - A web API Framework of golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

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

Application 全局应用对象

func App

func App() *Application

App() 生成全局Application对象

type Controller

type Controller struct {
	*Wrapper
	// contains filtered or unexported fields
}

Controller 控制器对象

type IController

type IController interface {
	// contains filtered or unexported methods
}

IController 控制器接口

type IMiddleware

type IMiddleware interface {
	Next()
	Handler()
	// contains filtered or unexported methods
}

IMiddleware 中间件接口

type IRouter

type IRouter interface {
	GET(name string, ctrl interface{}, middleware ...string)
	POST(name string, ctrl interface{}, middleware ...string)
	Add(methods, name string, ctrl interface{}, middleware ...string)
	Handler()
}

IRouter 路由接口

type Middleware

type Middleware struct {
	*Wrapper
	// contains filtered or unexported fields
}

Middleware 中间件对象

func (*Middleware) Next

func (m *Middleware) Next()

Next 调用下一个中间件

type Request

type Request struct {
	RawData string
	*http.Request
	// contains filtered or unexported fields
}

Request 请求对象

func NewRequest

func NewRequest(req *http.Request) *Request

NewRequest 创建Request对象

func (*Request) GetHeader

func (req *Request) GetHeader(key string) string

GetHeader 获取指定名称的请求头

func (*Request) Input

func (req *Request) Input(key string, defaultVal ...string) string

Input 获取指定的请求参数内容,以字符串类型返回

		Input(key) 获取请求参数,未设置时返回空字符串
     Input(key, defaultVal) 获取请求参数,不存在时返回defaultVal

func (*Request) Inputs

func (req *Request) Inputs(keys ...string) map[string]string

Inputs 返回指定的请求参数,返回map

Inputs() 获取全部请求参数
Inputs(key1, key2, ...) 返回指定的参数,不存在的参数值为空字符串

func (*Request) ParseJson

func (req *Request) ParseJson(result interface{}) error

ParseJson 将json字符串格式的原始数据decode到result

type Response

type Response struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Response 响应对象

func NewResponse

func NewResponse(writer http.ResponseWriter) *Response

NewResponse 创建新的响应对象

func (*Response) Fail

func (res *Response) Fail(code int, message string, data ...interface{})

Fail 输出json格式的错误响应

func (*Response) HttpStatus

func (res *Response) HttpStatus(code int, message ...string)

HttpStatus 输出特定响应码

func (*Response) OK

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

OK 输出json格式的正常响应

func (*Response) Resp

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

Resp 输出响应

func (*Response) SetHeader

func (res *Response) SetHeader(key, val string)

SetHeader 在响应中添加Header,在body输出前调用

type Router

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

Router 路由器对象

func (*Router) Add

func (r *Router) Add(method, name string, control interface{}, middleware ...string)

Add 添加路由

func (*Router) GET

func (r *Router) GET(name string, ctrl interface{}, middleware ...string)

GET 添加GET请求路由

func (*Router) Group

func (r *Router) Group(prefix, ctrl, middleware string, fn func())

Group 设置路由组

func (*Router) Handler

func (r *Router) Handler()

Handler 路由处理器

func (*Router) OPTIONS

func (r *Router) OPTIONS(name string, ctrl interface{}, middleware ...string)

OPTIONS 添加OPTIONS请求路由

func (*Router) POST

func (r *Router) POST(name string, ctrl interface{}, middleware ...string)

POST 添加POST请求路由

type Server

type Server struct {
}

Server 服务器对象

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (s *Server) Start()

Start 启动服务监听

func (*Server) Use

func (s *Server) Use(o interface{})

Use 声明路由、控制器、中间件

type Wrapper

type Wrapper struct {
	*Request
	*Response
	// contains filtered or unexported fields
}

Wrapper 对Request和ResponseWriter进行包装

func (*Wrapper) Add

func (ctx *Wrapper) Add(key, val string)

Add 添加内容至请求参数, 该参数可用Request的Input或Inputs方法读取,也不会被请求参数覆盖,

func (*Wrapper) Context

func (ctx *Wrapper) Context(key string, val ...interface{}) (result interface{})

Context 设置或读取上下文参数 Context(key string, val interface{}) 设置内容 Context(key string) 获取内容

Jump to

Keyboard shortcuts

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