net

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 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

View Source
const UA = "Mozilla/5.0(compatible; Telebot-Expansion-Pack/v1; +https://github.com/3JoB/telebot)"

Variables

This section is empty.

Functions

This section is empty.

Types

type FastHTTP

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

func (*FastHTTP) AcquireRequest

func (f *FastHTTP) AcquireRequest() NetRequest

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() (NetResponse, error)

func (*FastHTTPRequest) MethodGET

func (f *FastHTTPRequest) MethodGET()

func (*FastHTTPRequest) MethodPOST

func (f *FastHTTPRequest) MethodPOST()

func (*FastHTTPRequest) Release

func (f *FastHTTPRequest) Release()

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) SetUnmarshal added in v1.4.0

func (f *FastHTTPRequest) SetUnmarshal(v any)

func (*FastHTTPRequest) SetWriter

func (f *FastHTTPRequest) SetWriter(w io.Writer)

If this value is set, when reading data, the Body will be written directly to the set Writer interface without returning []byte.

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 FastHTTPResponse

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

func (*FastHTTPResponse) Bytes

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

func (*FastHTTPResponse) IsStatusCode

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

func (*FastHTTPResponse) Release

func (r *FastHTTPResponse) Release()

func (*FastHTTPResponse) Reset

func (r *FastHTTPResponse) Reset()

func (*FastHTTPResponse) StatusCode

func (r *FastHTTPResponse) StatusCode() int

type GoNet

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

func (*GoNet) AcquireRequest

func (g *GoNet) AcquireRequest() NetRequest

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() (NetResponse, error)

func (*GoNetRequest) MethodGET

func (g *GoNetRequest) MethodGET()

func (*GoNetRequest) MethodPOST

func (g *GoNetRequest) MethodPOST()

func (*GoNetRequest) Release

func (g *GoNetRequest) Release()

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) SetUnmarshal added in v1.4.0

func (g *GoNetRequest) SetUnmarshal(v any)

func (*GoNetRequest) SetWriter

func (g *GoNetRequest) SetWriter(w io.Writer)

If this value is set, when reading data, the Body will be written directly to the set Writer interface without returning []byte.

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 GoNetResponse

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

func (*GoNetResponse) Bytes

func (g *GoNetResponse) Bytes() []byte

func (*GoNetResponse) IsStatusCode

func (g *GoNetResponse) IsStatusCode(v int) bool

func (*GoNetResponse) Release

func (g *GoNetResponse) Release()

func (*GoNetResponse) Reset

func (g *GoNetResponse) Reset()

func (*GoNetResponse) StatusCode

func (g *GoNetResponse) StatusCode() int

type NetFrame

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

	// Create a new request object
	AcquireRequest() NetRequest
}

It is forbidden to use multiple Netframe at the same time! It will cause programs to appear Panic!

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 io.Writer)

	// Set an Unmarshal object, which will automatically execute Unmarshal
	// when the returned result is json (no need to manually execute Unmarshal)
	//
	// When Json Unmarshal is successfully executed, the Body content will no longer be returned.
	SetUnmarshal(v any)

	Write(b []byte)
	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() (NetResponse, 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()

	// This method is generally not recommended because the built-in methods
	// have automatically called Release() at the end of the Do() method,
	// and only Response needs to be called manually.
	//
	// Release() will clear the data in the current pointer and put it back
	// into the pool. After release, the corresponding pointer should not be used anymore.
	Release()
}

type NetResponse

type NetResponse interface {
	StatusCode() int
	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()

	// Release() will clear the data in the current pointer and put it back
	// into the pool. After release, the corresponding pointer should not be used anymore.
	Release()
}

Jump to

Keyboard shortcuts

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