http

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Overview

Package http

Package http

Package http

Package http

Package http

Package http

Package http

Package http

Package http

Package http

Index

Constants

View Source
const (
	ErrEngineEmpty  = "engine is not init"
	ErrServerClosed = "server is closed"
)
View Source
const (
	GET    = "GET"
	POST   = "POST"
	PUT    = "PUT"
	DELETE = "DELETE"
	PATCH  = "PATCH"
	OPTION = "OPTION"
)
View Source
const (
	REST   = "REST"
	HTML   = "HTML"
	STRING = "STRING"
	FILE   = "FILE"
)

Variables

This section is empty.

Functions

func ModuleName

func ModuleName() string

Types

type Address

type Address struct {
	Host   string   // 监听的HOST
	Port   int      // 监听的端口
	Domain []string // 用于校验refer的域名(非指定域名会直接屏蔽请求) 绑定域名后会默认校验refer
}

type Context

type Context struct {
	*gin.Context
}

func (*Context) BeforeResponse

func (c *Context) BeforeResponse()

BeforeResponse 响应前的处理

func (*Context) Response

func (c *Context) Response(t string, s int, data interface{})

Response 响应

func (*Context) ResponseAny

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

ResponseAny 不做类型推断返回stream

func (*Context) ResponseBad

func (c *Context) ResponseBad(t string, data interface{})

ResponseBad 错误响应500

func (*Context) ResponseFile

func (c *Context) ResponseFile(s int, f string)

ResponseFile alias of response with type file

func (*Context) ResponseGood

func (c *Context) ResponseGood(t string, data interface{})

ResponseGood 200响应

func (*Context) ResponseHtml

func (c *Context) ResponseHtml(s int, f string)

ResponseHtml alias of response with type html

func (*Context) ResponseREST

func (c *Context) ResponseREST(s int, data interface{})

ResponseREST alias of response with type rest

func (*Context) ResponseStr

func (c *Context) ResponseStr(s int, data string)

ResponseStr alias of response with type string

type Router

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

type RouterGroup

type RouterGroup struct {
	*gin.RouterGroup
}

type Server

type Server struct {
	EnableLog    bool                // 使用内置的日志打印 默认输出到控制台
	Logger       log.LoggerInterface // 使用的日志记录器 默认为内置日志
	Debug        bool                // 开启gin的debug
	RegSignal    []os.Signal         // 监听系统信号量
	Address      Address             // 监听地址
	Headers      map[string]string   // 自定义的Headers
	Copyright    string              // 版权所有 会以header: Copyright: xx的方式返回在响应中
	MaxBodySize  int                 // 最大请求体限制 默认1<<20 bytes
	ReadTimeout  int                 // 继承http.Server
	WriteTimeout int                 // 继承http.Server
	IdleTimeout  int                 // 继承http.Server
	// todo tls
	PProf bool // 是否开启pprof 路径为"debug/pprof"
	// contains filtered or unexported fields
}

func (*Server) Group

func (s *Server) Group(path string, wrap ...WrapperFunc) *RouterGroup

Group 路由分组

func (*Server) Init

func (s *Server) Init()

Init 在其他方法被调用前初始化

func (*Server) Listen

func (s *Server) Listen() error

func (*Server) ListenSmooth

func (s *Server) ListenSmooth()

ListenSmooth 平滑关闭 在注册监听signal的时候生效 默认注册CTRL+C

func (*Server) RegMiddle

func (s *Server) RegMiddle(mds ...Wrapper)

RegMiddle 注册中间件

func (*Server) RegSignals

func (s *Server) RegSignals(sigs ...os.Signal)

RegSignals 信号注册 默认为空时注册interrupt可能导致其他loop无法退出 所以仅在debug模式下注册此信号

func (*Server) Route

func (s *Server) Route(method, uri string, wrap ...WrapperFunc)

func (*Server) Run

func (s *Server) Run()

Run 不处理错误版本的listen

type Wrapper

type Wrapper struct {
	Name        string
	WrapperFunc WrapperFunc
}

type WrapperFunc

type WrapperFunc func(c *Context)

func MiddleWareCors added in v1.1.2

func MiddleWareCors() WrapperFunc

MiddleWareCors 默认的cors 允许所有跨域

func MiddleWareLogger added in v1.1.2

func MiddleWareLogger() WrapperFunc

MiddleWareLogger 路由日志

Jump to

Keyboard shortcuts

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