httputil

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package httputil provides helpers for constructing multipart HTTP requests.

Index

Constants

This section is empty.

Variables

View Source
var Client = &http.Client{Timeout: 30 * time.Second}

Client is a shared HTTP client with a 30-second timeout, used by all remote step packages to avoid indefinite hangs on unresponsive servers.

Functions

func CheckStatus added in v0.2.11

func CheckStatus(resp *http.Response, prefix string) error

CheckStatus returns an error if the response status code is not 2xx. The prefix is included in the error message for context (e.g. "discord: webhook").

func Post added in v0.2.21

func Post(url, contentType string, body io.Reader) (*http.Response, error)

Post issues a POST using the shared Client.

func PostForm added in v0.2.21

func PostForm(endpoint string, data url.Values) (*http.Response, error)

PostForm issues a POST with form data using the shared Client.

func PostMultipart added in v0.2.21

func PostMultipart(url string, upload FileUpload, fields [][2]string) (*http.Response, error)

PostMultipart builds a multipart form with a file attachment and text fields, then POSTs it using the shared Client. Fields are written before the file.

func ReadSnippet

func ReadSnippet(r io.Reader) string

ReadSnippet reads up to 200 bytes from r for inclusion in error messages.

Types

type FileUpload added in v0.2.21

type FileUpload struct {
	FieldName   string // form field name (e.g. "file", "audio", "voice")
	FilePath    string // path to the file on disk
	ContentType string // MIME type; empty uses application/octet-stream
}

FileUpload describes a file to include in a multipart form POST.

Jump to

Keyboard shortcuts

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