sohttp

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sohttp 符合goso net对象的 http 服务

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouters

func NewRouters(uris []string, httpMethods []string) []so.Router

NewRouters 获取路由

Types

type Config

type Config struct {
	Ports []int
}

Config 配置

type Router

type Router struct {
	HTTPMethod string
	URI        string
}

Router 路由器

func (*Router) String

func (router *Router) String() string

String 格式化方法

type SoHTTP

type SoHTTP struct {
	*gin.Engine
	Config           *Config
	Logger           logger.Logger
	GatePack         so.GatePack // gnet 用到
	ErrorNetFunc     func(code int, err error) interface{}
	BeforeHandleFunc func(soHTTP *SoHTTP, c *gin.Context, req interface{}) (context.Context, int, error)
	BehindHandleFunc func(ctx context.Context, soHTTP *SoHTTP, c *gin.Context, resp interface{}) (int, error)
	ConverHandleFunc func(soHTTP *SoHTTP, handle so.Handler) gin.HandlerFunc // so.HandlerFunc to gin.HandlerFunc
}

SoHTTP 符合goso net对象的 http 服务 BeforeHandleFunc handle 的 前置处理 BehindHandleFunc handle 的 后置处理 BeforeHandleFunc 和 BehindHandleFunc 返回的 code 由 ErrorNetFunc 处理 不设置 ErrorNetFunc, code 只能使用 httpcode, 默认使用 BadRequest 和 InternalServerError

func New

func New() (*SoHTTP, error)

New 默认http对象

func NewGNet

func NewGNet() (*SoHTTP, error)

NewGNet 一个新的 gnet http 对象 http 协议的 gnet 没啥实际价值, 请用专业的 api 网关

func NewLNet

func NewLNet() (*SoHTTP, error)

NewLNet 一个新的lnet gin 对象

func (*SoHTTP) Register

func (soHTTP *SoHTTP) Register(handler so.Handler) error

Register 注册处理器

func (*SoHTTP) SetBeforeHandleFunc added in v0.0.5

func (soHTTP *SoHTTP) SetBeforeHandleFunc(beforeHandleFunc func(soHTTP *SoHTTP, c *gin.Context, req interface{}) (context.Context, int, error)) error

SetBeforeHandleFunc 设置 响应编码方法

func (*SoHTTP) SetBehindHandleFunc added in v0.0.5

func (soHTTP *SoHTTP) SetBehindHandleFunc(behindHandleFunc func(ctx context.Context, soHTTP *SoHTTP, c *gin.Context, resp interface{}) (int, error)) error

SetBehindHandleFunc 设置 请求解码方法

func (*SoHTTP) SetConfig

func (soHTTP *SoHTTP) SetConfig(config *Config) error

SetConfig 设置 Config

func (*SoHTTP) SetConverHandleFunc

func (soHTTP *SoHTTP) SetConverHandleFunc(ConverHandleFunc func(soHTTP *SoHTTP, handle so.Handler) gin.HandlerFunc) error

SetConverHandleFunc 设置 ConverHandleFunc

func (*SoHTTP) SetErrorNetFunc

func (soHTTP *SoHTTP) SetErrorNetFunc(errFunc func(code int, err error) interface{}) error

SetErrorNetFunc 设置框架层错误处理

func (*SoHTTP) SetGatePack

func (soHTTP *SoHTTP) SetGatePack(gatePack so.GatePack) error

SetGatePack 设置包对象

func (*SoHTTP) SetLogger

func (soHTTP *SoHTTP) SetLogger(logger logger.Logger)

SetLogger 设置日志器

func (*SoHTTP) Start

func (soHTTP *SoHTTP) Start() error

Start 启动服务

func (*SoHTTP) Stop

func (soHTTP *SoHTTP) Stop() error

Stop 关闭服务

Jump to

Keyboard shortcuts

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