util

package
v1.5.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRedirect added in v1.3.9

func CheckRedirect(fun func(req *http.Request, via []*http.Request) error)

func DELETE

func DELETE(u string, opts ...Option) (raw json.RawMessage, err error)

func File

func File(u, method string, opts ...Option) (io io.Reader, err error)

func GET

func GET(u string, opts ...Option) (raw json.RawMessage, err error)

func GetCookie

func GetCookie(url *url.URL, name string) *http.Cookie

func Hash added in v1.5.8

func Hash(key, msg string) string

func JarDir added in v1.3.9

func JarDir() string

func MD5 added in v1.5.8

func MD5(msg string) []byte

func NewPrivateKey added in v1.5.8

func NewPrivateKey() (*ecdsa.PrivateKey, error)

func NewPrivateKeyFromBytes added in v1.5.8

func NewPrivateKeyFromBytes(priv []byte) *ecdsa.PrivateKey

func NewPrivateKeyFromHex added in v1.5.8

func NewPrivateKeyFromHex(hex_ string) (*ecdsa.PrivateKey, error)

func POST

func POST(u string, opts ...Option) (raw json.RawMessage, err error)

func PUT

func PUT(u string, opts ...Option) (raw json.RawMessage, err error)

func PrivateKeyToBytes added in v1.5.8

func PrivateKeyToBytes(private *ecdsa.PrivateKey) []byte

func PrivateKeyToHex added in v1.5.8

func PrivateKeyToHex(private *ecdsa.PrivateKey) string

func PublicKeyToBytes added in v1.5.8

func PublicKeyToBytes(public *ecdsa.PublicKey) []byte

func PublicKeyToHex added in v1.5.8

func PublicKeyToHex(public *ecdsa.PublicKey) string

func ReadFile

func ReadFile(filepath string, data interface{}) error

func RegisterDNS added in v1.3.7

func RegisterDNS(dns []string)

func RegisterFileJar added in v1.3.9

func RegisterFileJar()

func RegisterProxy added in v1.5.5

func RegisterProxy(proxy func(*http.Request) (*url.URL, error))

func Request added in v1.3.0

func Request(method, u string, opts ...Option) (json.RawMessage, http.Header, error)

func SOCKET

func SOCKET(u string, header map[string]string) (conn *websocket.Conn, raw json.RawMessage, err error)

func Sha256 added in v1.5.8

func Sha256(msg string) string

func SyncJar added in v1.3.9

func SyncJar()

func UserAgent

func UserAgent(args ...int) string

func WriteFile

func WriteFile(filepath string, data interface{}) error

Types

type CodeError

type CodeError struct {
	Method  string
	URL     string
	Code    int
	Message string
}

func (CodeError) Error

func (err CodeError) Error() string

type EmptyDialOption added in v1.5.0

type EmptyDialOption struct{}

Empty

type Group added in v1.3.0

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

Group represents a class of work and forms a namespace in which units of work can be executed with duplicate suppression.

func (*Group) Do added in v1.3.0

func (g *Group) Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool)

Do executes and returns the results of the given function, making sure that only one execution is in-flight for a given key at a time. If a duplicate comes in, the duplicate caller waits for the original to complete and receives the same results. The return value shared indicates whether v was given to multiple callers.

func (*Group) DoChan added in v1.3.0

func (g *Group) DoChan(key string, fn func() (interface{}, error)) <-chan Result

DoChan is like Do but returns a channel that will receive the results when they are ready.

The returned channel will not be closed.

func (*Group) Forget added in v1.3.0

func (g *Group) Forget(key string)

Forget tells the singleflight to forget about a key. Future calls to Do for this key will call the function rather than waiting for an earlier call to complete.

type Jar

type Jar struct {
	PsList cookiejar.PublicSuffixList `json:"pslist"`

	// mu locks the remaining fields.
	Mu sync.Mutex `json:"mu"`

	// entries is a set of entries, keyed by their eTLD+1 and subkeyed by
	// their name/domain/path.
	Entries map[string]map[string]entry `json:"entries"`

	// nextSeqNum is the next sequence number assigned to a new cookie
	// created SetCookies.
	NextSeqNum uint64 `json:"nextseqnum"`
}

type Option added in v1.5.0

type Option interface {
	// contains filtered or unexported methods
}

func WithAfterResponse added in v1.5.0

func WithAfterResponse(f func(w *http.Response)) Option

func WithBeforeRequest added in v1.5.0

func WithBeforeRequest(f func(r *http.Request)) Option

func WithBody added in v1.5.0

func WithBody(body interface{}) Option

func WithContext added in v1.5.0

func WithContext(ctx context.Context) Option

func WithHeader added in v1.5.0

func WithHeader(header map[string]string) Option

func WithProxy added in v1.5.8

func WithProxy(f func(*http.Request) (*url.URL, error)) Option

func WithRandomHost added in v1.5.8

func WithRandomHost(f func(string) string) Option

func WithRetry added in v1.5.0

func WithRetry(retry uint) Option

type Result added in v1.3.0

type Result struct {
	Val    interface{}
	Err    error
	Shared bool
}

Result holds the results of Do, so they can be passed on a channel.

Jump to

Keyboard shortcuts

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