httputil

package
v0.0.0-...-db8033e Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = HTTPTimeouts{
	ReadTimeout:       10 * time.Second,
	ReadHeaderTimeout: 10 * time.Second,
	WriteTimeout:      10 * time.Second,
	IdleTimeout:       15 * time.Second,
}

Functions

func NewHttpServer

func NewHttpServer(handler http.Handler) *http.Server

*

  • @Description: 创建一个http services
  • @param handler:请求处理器,用于处理请求

Types

type HTTPOption

type HTTPOption func(sev *HTTPServer) error

定义一个函数类型HTTPOption,返回值是error

func WithMaxHeaderBytes

func WithMaxHeaderBytes(max int) HTTPOption

func WithTimeouts

func WithTimeouts(timeouts HTTPTimeouts) HTTPOption

type HTTPServer

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

func StartHttpServer

func StartHttpServer(addr string, handler http.Handler, opts ...HTTPOption) (*HTTPServer, error)

*

  • @Description: 创建一个http services
  • @param addr:监听地址
  • @param handler:请求处理器,用于处理请求
  • @param opts:可变响应参数

func (*HTTPServer) Addr

func (hs *HTTPServer) Addr() net.Addr

func (*HTTPServer) Close

func (hs *HTTPServer) Close() error

func (*HTTPServer) Closed

func (hs *HTTPServer) Closed() bool

检查关闭状态

func (*HTTPServer) Shutdown

func (hs *HTTPServer) Shutdown(ctx context.Context) error

关闭http services

func (*HTTPServer) Stop

func (hs *HTTPServer) Stop(ctx context.Context) error

type HTTPTimeouts

type HTTPTimeouts struct {
	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
}

type WrappedResponseWriter

type WrappedResponseWriter struct {
	StatusCode  int
	ResponseLen int
	// contains filtered or unexported fields
}

func NewWrappedResponseWriter

func NewWrappedResponseWriter(w http.ResponseWriter) *WrappedResponseWriter

func (*WrappedResponseWriter) Header

func (w *WrappedResponseWriter) Header() http.Header

func (*WrappedResponseWriter) Write

func (w *WrappedResponseWriter) Write(bytes []byte) (int, error)

func (*WrappedResponseWriter) WriteHeader

func (w *WrappedResponseWriter) WriteHeader(StatusCode int)

Jump to

Keyboard shortcuts

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