net

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

net package is a dedicated hybrid network wrapper for TEP.

It may have some impact on performance due to one or more additional allocations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(w io.Writer, r io.Reader) (int64, error)

form fasthttp

Types

type FastHTTP

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

func (*FastHTTP) Acquire

func (f *FastHTTP) Acquire() (NetRequest, NetResponse)

func (*FastHTTP) Release

func (f *FastHTTP) Release(req NetRequest, resp NetResponse)

func (*FastHTTP) ReleaseRequest

func (f *FastHTTP) ReleaseRequest(r NetRequest)

func (*FastHTTP) ReleaseResponse

func (f *FastHTTP) ReleaseResponse(r NetResponse)

func (*FastHTTP) SetJsonHandle

func (f *FastHTTP) SetJsonHandle(v json.Json)

type FastHTTPRequest

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

func (*FastHTTPRequest) Body

func (f *FastHTTPRequest) Body() io.Writer

Body returns writer for populating request body.

func (*FastHTTPRequest) Do

func (f *FastHTTPRequest) Do() error

func (*FastHTTPRequest) MethodGET

func (f *FastHTTPRequest) MethodGET()

func (*FastHTTPRequest) MethodPOST

func (f *FastHTTPRequest) MethodPOST()

func (*FastHTTPRequest) Reset

func (f *FastHTTPRequest) Reset()

func (*FastHTTPRequest) SetContentType

func (f *FastHTTPRequest) SetContentType(v string)

func (*FastHTTPRequest) SetRequestURI

func (f *FastHTTPRequest) SetRequestURI(v string)

func (*FastHTTPRequest) SetWriteCloser

func (f *FastHTTPRequest) SetWriteCloser(v io.ReadWriteCloser)

func (*FastHTTPRequest) SetWriter

func (f *FastHTTPRequest) SetWriter(w *bytes.Buffer)

func (*FastHTTPRequest) Write

func (f *FastHTTPRequest) Write(b []byte)

func (*FastHTTPRequest) WriteFile

func (f *FastHTTPRequest) WriteFile(content string, r io.Reader) error

func (*FastHTTPRequest) WriteJson

func (f *FastHTTPRequest) WriteJson(v any) error

type GoNet

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

func (*GoNet) Acquire

func (g *GoNet) Acquire() (NetRequest, NetResponse)

func (*GoNet) Release

func (g *GoNet) Release(req NetRequest, resp NetResponse)

func (*GoNet) ReleaseRequest

func (g *GoNet) ReleaseRequest(r NetRequest)

func (*GoNet) ReleaseResponse

func (g *GoNet) ReleaseResponse(r NetResponse)

func (*GoNet) SetJsonHandle

func (g *GoNet) SetJsonHandle(v json.Json)

type GoNetRequest

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

func (*GoNetRequest) Body

func (g *GoNetRequest) Body() io.Writer

Body returns writer for populating request body.

func (*GoNetRequest) Do

func (g *GoNetRequest) Do() error

func (*GoNetRequest) MethodGET

func (g *GoNetRequest) MethodGET()

func (*GoNetRequest) MethodPOST

func (g *GoNetRequest) MethodPOST()

func (*GoNetRequest) Reset

func (g *GoNetRequest) Reset()

func (*GoNetRequest) SetContentType

func (g *GoNetRequest) SetContentType(v string)

func (*GoNetRequest) SetRequestURI

func (g *GoNetRequest) SetRequestURI(v string)

func (*GoNetRequest) SetWriteCloser

func (g *GoNetRequest) SetWriteCloser(v io.ReadWriteCloser)

func (*GoNetRequest) SetWriter

func (g *GoNetRequest) SetWriter(w *bytes.Buffer)

func (*GoNetRequest) Write

func (g *GoNetRequest) Write(b []byte)

func (*GoNetRequest) WriteFile

func (g *GoNetRequest) WriteFile(content string, r io.Reader) error

func (*GoNetRequest) WriteJson

func (g *GoNetRequest) WriteJson(v any) error

type NetFrame

type NetFrame interface {
	// Set up Json handler
	SetJsonHandle(v json.Json)

	// Create a new request object
	Acquire() (NetRequest, NetResponse)

	ReleaseRequest(r NetRequest)

	ReleaseResponse(r NetResponse)

	Release(req NetRequest, resp NetResponse)
}

func NewFastHTTPClient

func NewFastHTTPClient() NetFrame

func NewHTTPClient

func NewHTTPClient() NetFrame

type NetRequest

type NetRequest interface {
	// Set the request method to POST.
	MethodPOST()

	// Set the request method to GET。
	MethodGET()

	// Only fasthttp
	Body() io.Writer

	// Set Content-Type
	SetContentType(v string)

	// Set the requested URI address
	SetRequestURI(v string)

	// Set a Writer. When this Writer is passed in,
	// the data will be written directly to the Writer
	// after the request is completed instead of passing in the Response.
	SetWriter(w *bytes.Buffer)

	// Set a Writer. When this Writer is passed in,
	// the data will be written directly to the Writer
	// after the request is completed instead of passing in the Response.
	SetWriteCloser(v io.ReadWriteCloser)

	// Write data to the Body.
	Write(b []byte)

	// Write files to Body.
	WriteFile(content string, r io.Reader) error

	// Write the structure directly to the Body as json,
	// which will be processed by the interface.
	WriteJson(v any) error

	// Execute request.
	Do() error

	// Release() will clear the data in the current pointer.
	// It is recommended to call it within the Release() method instead
	// of calling it externally.
	Reset()
}

type NetResponse

type NetResponse interface {
	// StatusCode method returns the HTTP status code for the executed request.
	//
	//	Example: 200
	StatusCode() int

	// Example:
	//
	//	Raw: 200
	//	fmt.Println(resp.IsStatusCode(444))
	//
	//	Output: false
	IsStatusCode(v int) bool

	// If SetWriter() is called in req, this method will
	// not be set (unless the status code is not 200)
	Bytes() []byte

	// Release() will clear the data in the current pointer.
	// It is recommended to call it within the Release() method instead
	// of calling it externally.
	Reset()
}

type Response

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

func (*Response) Bytes

func (r *Response) Bytes() []byte

func (*Response) IsStatusCode

func (r *Response) IsStatusCode(v int) bool

func (*Response) Reset

func (r *Response) Reset()

func (*Response) StatusCode

func (r *Response) StatusCode() int

Jump to

Keyboard shortcuts

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