util

package
v1.5.13 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DELETE

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

func Dir added in v1.5.11

func Dir() string

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 MD5 added in v1.5.8

func MD5(msg string) []byte

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 ReadFile

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

func RegisterConnTimeout added in v1.5.13

func RegisterConnTimeout(timeout, longTimeout time.Duration)

func RegisterCookieFun added in v1.5.11

func RegisterCookieFun(name string)

func RegisterCookieJar added in v1.5.11

func RegisterCookieJar(name string)

func RegisterDNS added in v1.3.7

func RegisterDNS(dns []string)

func RegisterDNSTimeout added in v1.5.13

func RegisterDNSTimeout(timeout time.Duration)

func RegisterDialerTimeout added in v1.5.13

func RegisterDialerTimeout(timeout time.Duration)

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 Sha256 added in v1.5.8

func Sha256(msg string) string

func UserAgent

func UserAgent(args ...int) string

func WriteFile

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

Types

type ClientOption added in v1.5.11

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

func WithClientCookieFun added in v1.5.11

func WithClientCookieFun(name string) ClientOption

func WithClientCookieJar added in v1.5.11

func WithClientCookieJar(name string) ClientOption

func WithClientDNS added in v1.5.11

func WithClientDNS(dns []string) ClientOption

func WithClientProxy added in v1.5.11

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

func WithConnTimeout added in v1.5.13

func WithConnTimeout(timeout, longTimeout time.Duration) ClientOption

func WithDNSTimeout added in v1.5.13

func WithDNSTimeout(timeout time.Duration) ClientOption

func WithDialerTimeout added in v1.5.13

func WithDialerTimeout(timeout time.Duration) ClientOption

type CodeError

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

func (CodeError) Error

func (err CodeError) Error() string

type EmbedClient added in v1.5.11

type EmbedClient struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewClient added in v1.5.11

func NewClient(opts ...ClientOption) *EmbedClient

func (*EmbedClient) DELETE added in v1.5.11

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

func (*EmbedClient) File added in v1.5.11

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

func (*EmbedClient) GET added in v1.5.11

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

func (*EmbedClient) GetCookie added in v1.5.11

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

func (*EmbedClient) GetCookies added in v1.5.13

func (c *EmbedClient) GetCookies(url *url.URL) []*http.Cookie

func (*EmbedClient) POST added in v1.5.11

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

func (*EmbedClient) PUT added in v1.5.11

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

func (*EmbedClient) Request added in v1.5.11

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

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 WithDebug added in v1.5.11

func WithDebug() 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

func WithTest added in v1.5.11

func WithTest() 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