httputils

package
v0.234.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const STATUS_CODE_OK = 200

Variables

View Source
var ErrWebServerAlreadyRunning = errors.New("web server already running")

Functions

This section is empty.

Types

type Client

type Client interface {
	DownloadAsFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File, err error)
	DownloadAsTemporaryFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File, err error)
	SendRequest(requestOptions *RequestOptions) (response Response, err error)
	MustDownloadAsFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File)
	MustDownloadAsTemporaryFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File)
	MustSendRequest(requestOptions *RequestOptions) (response Response)
}

func GetNativeClient

func GetNativeClient() (client Client)

Get the HTTP client written using native go http implementation.

This is the default client to use when sending request from your running machine.

type DownloadAsFileOptions

type DownloadAsFileOptions struct {
	RequestOptions    *RequestOptions
	OutputPath        string
	OverwriteExisting bool
	Verbose           bool
}

func NewDownloadAsFileOptions

func NewDownloadAsFileOptions() (d *DownloadAsFileOptions)

func (*DownloadAsFileOptions) GetDeepCopy

func (d *DownloadAsFileOptions) GetDeepCopy() (copy *DownloadAsFileOptions)

func (*DownloadAsFileOptions) GetOutputPath

func (d *DownloadAsFileOptions) GetOutputPath() (outputPath string, err error)

func (*DownloadAsFileOptions) GetOverwriteExisting

func (d *DownloadAsFileOptions) GetOverwriteExisting() (overwriteExisting bool)

func (*DownloadAsFileOptions) GetRequestOptions

func (d *DownloadAsFileOptions) GetRequestOptions() (requestOptions *RequestOptions, err error)

func (*DownloadAsFileOptions) GetVerbose

func (d *DownloadAsFileOptions) GetVerbose() (verbose bool)

func (*DownloadAsFileOptions) MustGetOutputPath

func (d *DownloadAsFileOptions) MustGetOutputPath() (outputPath string)

func (*DownloadAsFileOptions) MustGetRequestOptions

func (d *DownloadAsFileOptions) MustGetRequestOptions() (requestOptions *RequestOptions)

func (*DownloadAsFileOptions) MustSetOutputPath

func (d *DownloadAsFileOptions) MustSetOutputPath(outputPath string)

func (*DownloadAsFileOptions) MustSetRequestOptions

func (d *DownloadAsFileOptions) MustSetRequestOptions(requestOptions *RequestOptions)

func (*DownloadAsFileOptions) SetOutputPath

func (d *DownloadAsFileOptions) SetOutputPath(outputPath string) (err error)

func (*DownloadAsFileOptions) SetOverwriteExisting

func (d *DownloadAsFileOptions) SetOverwriteExisting(overwriteExisting bool)

func (*DownloadAsFileOptions) SetRequestOptions

func (d *DownloadAsFileOptions) SetRequestOptions(requestOptions *RequestOptions) (err error)

func (*DownloadAsFileOptions) SetVerbose

func (d *DownloadAsFileOptions) SetVerbose(verbose bool)

type GenericResponse

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

This is the generic response type. It can also be seen as the default response to use.

func NewGenericResponse

func NewGenericResponse() (g *GenericResponse)

func (*GenericResponse) GetBody

func (g *GenericResponse) GetBody() (body []byte, err error)

func (*GenericResponse) GetBodyAsString

func (g *GenericResponse) GetBodyAsString() (body string, err error)

func (*GenericResponse) GetStatusCode

func (g *GenericResponse) GetStatusCode() (statusCode int, err error)

func (*GenericResponse) IsStatusCodeOk

func (g *GenericResponse) IsStatusCodeOk() (isStatusCodeOk bool, err error)

func (*GenericResponse) MustGetBody

func (g *GenericResponse) MustGetBody() (body []byte)

func (*GenericResponse) MustGetBodyAsString

func (g *GenericResponse) MustGetBodyAsString() (body string)

func (*GenericResponse) MustGetStatusCode

func (g *GenericResponse) MustGetStatusCode() (statusCode int)

func (*GenericResponse) MustIsStatusCodeOk

func (g *GenericResponse) MustIsStatusCodeOk() (isStatusCodeOk bool)

func (*GenericResponse) MustSetBody

func (g *GenericResponse) MustSetBody(body []byte)

func (*GenericResponse) MustSetStatusCode

func (g *GenericResponse) MustSetStatusCode(statusCode int)

func (*GenericResponse) SetBody

func (g *GenericResponse) SetBody(body []byte) (err error)

func (*GenericResponse) SetStatusCode

func (g *GenericResponse) SetStatusCode(statusCode int) (err error)

type NativeClient

type NativeClient struct {
}

HTTP client written using native go http implementation.

func NewNativeClient

func NewNativeClient() (n *NativeClient)

func (*NativeClient) DownloadAsFile

func (n *NativeClient) DownloadAsFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File, err error)

func (*NativeClient) DownloadAsTemporaryFile

func (n *NativeClient) DownloadAsTemporaryFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File, err error)

func (*NativeClient) MustDownloadAsFile

func (n *NativeClient) MustDownloadAsFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File)

func (*NativeClient) MustDownloadAsTemporaryFile

func (n *NativeClient) MustDownloadAsTemporaryFile(downloadOptions *DownloadAsFileOptions) (downloadedFile files.File)

func (*NativeClient) MustSendRequest

func (n *NativeClient) MustSendRequest(requestOptions *RequestOptions) (response Response)

func (*NativeClient) SendRequest

func (c *NativeClient) SendRequest(requestOptions *RequestOptions) (response Response, err error)

type RequestOptions

type RequestOptions struct {
	// Url to request
	Url string

	// Port to use.
	// Overrides the port defined in URL if specified.
	Port int

	// Request method like GET, POST...
	Method string

	// Enable verbose output
	Verbose bool
}

func NewRequestOptions

func NewRequestOptions() (r *RequestOptions)

func (*RequestOptions) GetDeepCopy

func (r *RequestOptions) GetDeepCopy() (copy *RequestOptions)

func (*RequestOptions) GetMethod

func (r *RequestOptions) GetMethod() (method string, err error)

func (*RequestOptions) GetPort

func (r *RequestOptions) GetPort() (port int, err error)

func (*RequestOptions) GetUrl

func (r *RequestOptions) GetUrl() (url string, err error)

func (*RequestOptions) GetVerbose

func (r *RequestOptions) GetVerbose() (verbose bool)

func (*RequestOptions) MustGetMethod

func (r *RequestOptions) MustGetMethod() (method string)

func (*RequestOptions) MustGetPort

func (r *RequestOptions) MustGetPort() (port int)

func (*RequestOptions) MustGetUrl

func (r *RequestOptions) MustGetUrl() (url string)

func (*RequestOptions) MustSetMethod

func (r *RequestOptions) MustSetMethod(method string)

func (*RequestOptions) MustSetPort

func (r *RequestOptions) MustSetPort(port int)

func (*RequestOptions) MustSetUrl

func (r *RequestOptions) MustSetUrl(url string)

func (*RequestOptions) SetMethod

func (r *RequestOptions) SetMethod(method string) (err error)

func (*RequestOptions) SetPort

func (r *RequestOptions) SetPort(port int) (err error)

func (*RequestOptions) SetUrl

func (r *RequestOptions) SetUrl(url string) (err error)

func (*RequestOptions) SetVerbose

func (r *RequestOptions) SetVerbose(verbose bool)

type Response

type Response interface {
	GetBodyAsString() (body string, err error)
	IsStatusCodeOk() (isStatusCodeOK bool, err error)
	MustGetBodyAsString() (body string)
	MustIsStatusCodeOk() (isStatusCodeOK bool)
	SetBody(body []byte) (err error)
	SetStatusCode(statusCode int) (err error)
}

type Server

type Server interface {
	GetPort() (port int, err error)
	StartInBackground(verbose bool) (err error)
	Stop(verbose bool) (err error)
	MustGetPort() (port int)
	MustStartInBackground(verbose bool)
	MustStop(verbose bool)
}

func GetTestWebServer

func GetTestWebServer(port int) (webServer Server, err error)

func MustGetTestWebServer

func MustGetTestWebServer(port int) (webServer Server)

type TestWebServer

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

A simple webserver mostly used for testing.

func NewTestWebServer

func NewTestWebServer() (t *TestWebServer)

func (*TestWebServer) GetMux

func (t *TestWebServer) GetMux() (mux *http.ServeMux, err error)

func (*TestWebServer) GetPort

func (t *TestWebServer) GetPort() (port int, err error)

func (*TestWebServer) GetServer

func (t *TestWebServer) GetServer() (server *http.Server, err error)

func (*TestWebServer) GetWebServerWaitGroup

func (t *TestWebServer) GetWebServerWaitGroup() (webServerWaitGroup *sync.WaitGroup, err error)

func (*TestWebServer) MustGetMux

func (t *TestWebServer) MustGetMux() (mux *http.ServeMux)

func (*TestWebServer) MustGetPort

func (t *TestWebServer) MustGetPort() (port int)

func (*TestWebServer) MustGetServer

func (t *TestWebServer) MustGetServer() (server *http.Server)

func (*TestWebServer) MustGetWebServerWaitGroup

func (t *TestWebServer) MustGetWebServerWaitGroup() (webServerWaitGroup *sync.WaitGroup)

func (*TestWebServer) MustSetMux

func (t *TestWebServer) MustSetMux(mux *http.ServeMux)

func (*TestWebServer) MustSetPort

func (t *TestWebServer) MustSetPort(port int)

func (*TestWebServer) MustSetServer

func (t *TestWebServer) MustSetServer(server *http.Server)

func (*TestWebServer) MustSetWebServerWaitGroup

func (t *TestWebServer) MustSetWebServerWaitGroup(webServerWaitGroup *sync.WaitGroup)

func (*TestWebServer) MustStartInBackground

func (t *TestWebServer) MustStartInBackground(verbose bool)

func (*TestWebServer) MustStop

func (t *TestWebServer) MustStop(verbose bool)

func (*TestWebServer) SetMux

func (t *TestWebServer) SetMux(mux *http.ServeMux) (err error)

func (*TestWebServer) SetPort

func (t *TestWebServer) SetPort(port int) (err error)

func (*TestWebServer) SetServer

func (t *TestWebServer) SetServer(server *http.Server) (err error)

func (*TestWebServer) SetWebServerWaitGroup

func (t *TestWebServer) SetWebServerWaitGroup(webServerWaitGroup *sync.WaitGroup) (err error)

func (*TestWebServer) StartInBackground

func (t *TestWebServer) StartInBackground(verbose bool) (err error)

func (*TestWebServer) Stop

func (t *TestWebServer) Stop(verbose bool) (err error)

Jump to

Keyboard shortcuts

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