sohttp

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	ContextPrefix = "ctx-"
)

常量

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{}
	PreHandleFunc    func(soHTTP *SoHTTP, c *gin.Context, req interface{}) (context.Context, int, error)
	PostHandleFunc   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 服务 PreHandleFunc handle 的 前置处理 PostHandleFunc handle 的 后置处理 PreHandleFunc 和 PostHandleFunc 返回的 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) GetPrivateData

func (soHTTP *SoHTTP) GetPrivateData() interface{}

GetPrivateData 获取私有数据

func (*SoHTTP) Register

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

Register 注册处理器

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) SetPostHandleFunc

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

SetPostHandleFunc 设置 请求解码方法

func (*SoHTTP) SetPreHandleFunc

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

SetPreHandleFunc 设置 响应编码方法

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