network

package
v0.0.0-...-4bec719 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOption = Option{
	Addr:           ":8080",
	ReadTimeout:    10 * time.Second,
	WriteTimeout:   10 * time.Second,
	MaxHeaderBytes: 1 << 20,
}

Functions

func CookieHandler

func CookieHandler(w http.ResponseWriter, req *http.Request)

func IpInt2Str

func IpInt2Str(i uint32) string

func IpStr2Int

func IpStr2Int(ipStr string) uint32

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

Types

type ChiRouter

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

type HttpClient

type HttpClient struct {
	*http.Client
}

func NewHttpClient

func NewHttpClient() *HttpClient

func (*HttpClient) Get

func (c *HttpClient) Get(url string, header map[string]string) (*http.Response, error)

func (*HttpClient) PostFile

func (c *HttpClient) PostFile(url string, header map[string]string, filePath string) (*http.Response, error)

PostFile 一般是服务器发送响应才发送文件

func (*HttpClient) PostJson

func (c *HttpClient) PostJson(url string, header map[string]string, body map[string]any) (*http.Response, error)

func (*HttpClient) Req

func (c *HttpClient) Req(method, url string, header map[string]string, body io.Reader) (*http.Response, error)

type HttpServer

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

func New

func New(router *http.ServeMux) *HttpServer

func NewWithOption

func NewWithOption(router *http.ServeMux, option Option) *HttpServer

func (*HttpServer) Handle

func (s *HttpServer) Handle(pattern string, handler http.Handler)

func (*HttpServer) HandleFunc

func (s *HttpServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*HttpServer) Start

func (s *HttpServer) Start()

func (*HttpServer) Stop

func (s *HttpServer) Stop()

type Middleware

type Middleware func(http.Handler) http.Handler

type Option

type Option struct {
	Addr           string
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	MaxHeaderBytes int
}

Jump to

Keyboard shortcuts

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