httpUtils

package
v0.0.0-...-251d348 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultHttpClient *http.Client
)

Functions

func DownloadFile

func DownloadFile(b *gotgbot.Bot, fileID string) (io.ReadCloser, error)

func DownloadFileFromGetFile

func DownloadFileFromGetFile(b *gotgbot.Bot, file *gotgbot.File) (io.ReadCloser, error)

func MakeRequest

func MakeRequest(opts RequestOptions) error

func MultiPartFormRequest

func MultiPartFormRequest(url string, params []MultiPartParam, files []MultiPartFile) (*http.Response, error)

func MultiPartFormRequestWithHeaders

func MultiPartFormRequestWithHeaders(url string, headers map[string]string, params []MultiPartParam, files []MultiPartFile) (*http.Response, error)

Types

type HTTPMethod

type HTTPMethod string
const (
	MethodGet  HTTPMethod = http.MethodGet
	MethodPost HTTPMethod = http.MethodPost
)

type HttpError

type HttpError struct {
	StatusCode int
}

func (*HttpError) Error

func (e *HttpError) Error() string

func (*HttpError) StatusText

func (e *HttpError) StatusText() string

type MultiPartFile

type MultiPartFile struct {
	FieldName string
	FileName  string
	Content   io.Reader
}

type MultiPartParam

type MultiPartParam struct {
	Name  string
	Value string
}

type RequestOptions

type RequestOptions struct {
	Method  HTTPMethod
	URL     string
	Headers map[string]string
	Body    any

	// Response can either be a pointer to a JSON struct or a pointer to a string
	Response any
	// ErrorResponse can either be a pointer to a JSON struct or a pointer to a string.
	// NOTE: An error will still be returned!
	ErrorResponse any

	Client *http.Client
}

Jump to

Keyboard shortcuts

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