common

package
v0.0.0-...-cea0af2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INFINITY = -1
	DEFAULT  = 0
)

Variables

View Source
var (
	DebugMode  = false
	LogFactory log.Factory
)

Functions

func CopyResponse

func CopyResponse(w http.ResponseWriter, resp *http.Response) error

func FixRequest

func FixRequest(r *http.Request)

func GetCacheKey

func GetCacheKey(req *http.Request) string

func GetValueFromContext

func GetValueFromContext[T any](ctx context.Context, key string) (ret T, ok bool)

func IsIgnoredError

func IsIgnoredError(err error) bool

func IsNetCancelError

func IsNetCancelError(err error) bool

func IsRequestCachable

func IsRequestCachable(req *http.Request) bool

func NewHttpClient

func NewHttpClient(tr http.RoundTripper) *http.Client

func NewLogger

func NewLogger(name string) log.ContextLogger

func NewPeekedConn

func NewPeekedConn(c net.Conn, r io.Reader) net.Conn

func RandomString

func RandomString(length int) string

func SpawnPprofServer

func SpawnPprofServer(port int)

func WrapCompressedReader

func WrapCompressedReader(r io.Reader, encoding string) (io.ReadCloser, error)

Types

type AutoFallbackClient

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

use http2 first and fallback to http1.1 if failed

func NewAutoFallbackClient

func NewAutoFallbackClient() *AutoFallbackClient

func (*AutoFallbackClient) Do

func (*AutoFallbackClient) RoundTrip

func (c *AutoFallbackClient) RoundTrip(req *http.Request) (*http.Response, error)

type Cleaner

type Cleaner struct {
	Interval time.Duration
	// contains filtered or unexported fields
}

func (*Cleaner) Cleaning

func (c *Cleaner) Cleaning(cache *cache)

type Data

type Data struct {
	Value    interface{}
	ExpireAt time.Time
}

type HTTPRequestDoer

type HTTPRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

type PeekedConn

type PeekedConn struct {
	net.Conn
	// contains filtered or unexported fields
}

A peekedConn subverts the net.Conn.Read implementation, primarily so that sniffed bytes can be transparently prepended.

func (*PeekedConn) Read

func (c *PeekedConn) Read(buf []byte) (int, error)

Read allows control over the embedded net.Conn's read data. By using an io.MultiReader one can read from a conn, and then replace what they read, to be read again.

type TTLCache

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

func NewTTLCache

func NewTTLCache(defaultExpiryDuration time.Duration, cleanUpInterval time.Duration) *TTLCache

func (TTLCache) Delete

func (c TTLCache) Delete(key string)

func (TTLCache) Get

func (c TTLCache) Get(key string) (interface{}, bool)

func (TTLCache) Set

func (c TTLCache) Set(key string, value interface{})

Jump to

Keyboard shortcuts

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