multipart

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyBody         = errors.New("multipart body is empty")
	ErrInvalidFileType   = errors.New("invalid file type")
	ErrInvalidBaseURL    = errors.New("invalid base URL")
	ErrFailedToCreateReq = errors.New("failed to create request")
	ErrRequestFailed     = errors.New("request execution failed")
	ErrUnexpectedStatus  = errors.New("upload failed: unexpected status code")
)

Functions

func NewTool

func NewTool(c Client, opts contract.ToolOptions[Client]) *defaultTool

Types

type Client

type Client interface {
	NewMultipartBody(ctx context.Context, file []byte, fileName string) (io.Reader, string, error)
	Store(ctx context.Context, r *http.Request, opts StoreOptions) error
}

func NewClient

func NewClient(hr contract.HTTPRequester, hd contract.HTTPDoer) (Client, error)

type StoreOption

type StoreOption func(*StoreOptions)

func WithBaseURL

func WithBaseURL(url string) StoreOption

func WithBody

func WithBody(body io.Reader) StoreOption

func WithExpectedStatus

func WithExpectedStatus(status int) StoreOption

func WithFormDataContentType

func WithFormDataContentType(contentType string) StoreOption

func WithForwardHeaders

func WithForwardHeaders(headers ...string) StoreOption

func WithQueryParams

func WithQueryParams(q url.Values) StoreOption

type StoreOptions

type StoreOptions struct {
	BaseURL             string
	QueryParams         url.Values
	Body                io.Reader
	ForwardHeaders      []string
	FormDataContentType string
	ExpectedStatus      int
}

func ApplyStoreOptions

func ApplyStoreOptions(opts *StoreOptions, modifiers ...StoreOption) StoreOptions

type UploadParams

type UploadParams struct {
	Body                io.Reader
	QueryParams         map[string][]string
	BaseUrl             string
	FormDataContentType string
	ExpectedStatus      int
}

Jump to

Keyboard shortcuts

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