httpclient

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultHTTPTimeout は、デフォルトのHTTPタイムアウトです。
	DefaultHTTPTimeout = 30 * time.Second
	// MaxResponseBodySize は、あらゆるHTTPレスポンスボディの最大読み込みサイズです。
	MaxResponseBodySize = int64(25 * 1024 * 1024) // 25MB
	// UserAgent は、サイトからのブロックを避けるためのUser-Agentです。
	UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
)

Variables

This section is empty.

Functions

func HandleLimitedResponse added in v1.0.8

func HandleLimitedResponse(resp *http.Response, limit int64) ([]byte, error)

HandleLimitedResponse は、指定されたレスポンスボディを、最大サイズに制限して読み込みます。 Notifier パッケージから httpclient.HandleLimitedResponse(resp, limit) として呼び出されます。

func IsNonRetryableError

func IsNonRetryableError(err error) bool

IsNonRetryableError は与えられたエラーが非リトライ対象のHTTPエラーであるかを判断します。

Types

type Client

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

Client はHTTPリクエストと指数バックオフを用いたリトライロジックを管理します。

func New

func New(timeout time.Duration, options ...ClientOption) *Client

New は新しいClientを初期化します。 optionsはオプションの設定を受け取ります。

func (*Client) Do added in v1.0.7

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do は HTTPClient インターフェースが持つ Do メソッドを呼び出すラッパーです。 これにより、Client 型が HTTPClient インターフェースを満たします。

func (*Client) FetchDocument

func (c *Client) FetchDocument(url string, ctx context.Context) (*goquery.Document, error)

FetchDocument はURLからHTMLを取得し、goquery.Documentを返します。

func (*Client) PostJSONAndFetchBytes

func (c *Client) PostJSONAndFetchBytes(url string, data any, ctx context.Context) ([]byte, error)

PostJSONAndFetchBytes は指定されたデータをJSONとしてPOSTし、レスポンスボディをバイト配列として返します。

type ClientOption added in v1.0.5

type ClientOption func(*Client)

ClientOption はClientの設定を行うための関数型です。

func WithHTTPClient added in v1.0.5

func WithHTTPClient(client HTTPClient) ClientOption

WithHTTPClient はカスタムのHTTPClientを設定します。

func WithMaxRetries added in v1.0.7

func WithMaxRetries(max uint64) ClientOption

WithMaxRetries は最大リトライ回数を設定します。

type HTTPClient added in v1.0.5

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

HTTPClient は、*http.Clientと互換性のあるHTTPクライアントのインターフェースを定義します。

type NonRetryableHTTPError

type NonRetryableHTTPError struct {
	StatusCode int
	Body       []byte
}

NonRetryableHTTPError はHTTP 4xx系のステータスコードエラーを示すカスタムエラー型です。

func (*NonRetryableHTTPError) Error

func (e *NonRetryableHTTPError) Error() string

Error は NonRetryableHTTPError のエラーメッセージを返します。

Jump to

Keyboard shortcuts

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