http

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 正常
	OK int = 0
	// 参数错误
	ParamsError int = 4001
	// 数据错误
	DataError int = 4002
)

Variables

View Source
var (
	ErrHTMLRenderUndefined   = errors.New("html render is undefined")
	ErrHTMLRenderTemplateNil = errors.New("html render's template is nil")
	ErrTemplateUndefined     = errors.New("template is undefined")
)

Functions

func BodyLog

func BodyLog() gin.HandlerFunc

BodyLog HTTP 响应体输出

func CachePage

func CachePage(cache *cache.Cache) gin.HandlerFunc

CachePage sees if there are any cached responses and returns the cached response if one is available.

func Minify

func Minify(m *minify.M, mediaType string) gin.HandlerFunc

func NewMinifyResponseWriter

func NewMinifyResponseWriter(m *minify.M, w gin.ResponseWriter, r *http.Request) *minifyResponseWriter

**************************************************************************** NewMinifyResponseWriter 创建 NewMinifyResponseWriter

func PipeWriter

func PipeWriter(m *minify.M, mediatype string, w io.Writer) *minifyWriter

Types

type BodyWriter

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

func NewBodyWriter

func NewBodyWriter(cfg *config.Config) *BodyWriter

func (*BodyWriter) Configure

func (b *BodyWriter) Configure(s *Server)

type CacheWriter

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

func NewCacheWriter

func NewCacheWriter(cfg *config.Config) *CacheWriter

func (*CacheWriter) Configure

func (c *CacheWriter) Configure(s *Server)

type HTMLRender

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

func NewHTMLRender

func NewHTMLRender() *HTMLRender

func (*HTMLRender) Bytes

func (r *HTMLRender) Bytes(name string, data interface{}) ([]byte, error)

func (*HTMLRender) Configure

func (r *HTMLRender) Configure(s *Server)

func (*HTMLRender) MustBytes

func (r *HTMLRender) MustBytes(name string, data interface{}) []byte

func (*HTMLRender) MustString

func (r *HTMLRender) MustString(name string, data interface{}) string

func (*HTMLRender) Output

func (r *HTMLRender) Output(w io.Writer, name string, data interface{}) error

func (*HTMLRender) String

func (r *HTMLRender) String(name string, data interface{}) (string, error)

type MinifyWriter

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

func NewMinifyWriter

func NewMinifyWriter(cfg *config.Config) *MinifyWriter

func (*MinifyWriter) Configure

func (c *MinifyWriter) Configure(s *Server)

type Response

type Response struct {
	// 是否成功
	Success bool `json:"success"`
	// 错误代码
	ErrorCode int `json:"error_code"`
	// 消息
	Message string `json:"message"`
	// 数据项
	Data interface{} `json:"data"`
}

Response Http响应

func NewResponse

func NewResponse(errCode int, msg string, data ...interface{}) *Response

NewResponse 创建响应

func NewResponseError

func NewResponseError(err interface{}, data ...interface{}) *Response

NewResponseError 创建错误响应, 显示原始错误

func NewResponseOK

func NewResponseOK(msg string, data ...interface{}) *Response

NewResponseOK 创建成功响应

type Server

type Server struct {
	*gin.Engine
	Addr string
}

Server

func Default

func Default() *Server

Default 创建默认HTTP Sever

func New

func New() *Server

New 创建HTTP Sever

func NewServer

func NewServer(cs []ServerConfigurator) *Server

NewServer 使用配置器初始化服务器

func (*Server) Configure

func (s *Server) Configure(cs ...ServerConfigurator)

Configure 配置

func (*Server) Run

func (s *Server) Run(addr ...string) error

Run 监听端口并运行服务器

func (*Server) StdServer

func (s *Server) StdServer(conf *config.Server) *stdhttp.Server

StdServer 标准HTTP服务器

type ServerConfigurator

type ServerConfigurator interface {
	Configure(*Server)
}

ServerConfigurator 服务器配置接口

func WithAddr

func WithAddr(addr string) ServerConfigurator

WithAddr 配置主机服务地址

func WithRenderTemplates

func WithRenderTemplates(pattern string) ServerConfigurator

WithRenderTemplates 配置要呈现的模板路径

func WithTemplateFuncMap

func WithTemplateFuncMap(funcMap template.FuncMap) ServerConfigurator

WithTemplateFuncMap 模板函数配置

Jump to

Keyboard shortcuts

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