http

package
v0.0.0-...-ed34e12 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 13 Imported by: 0

README

Net:Http Protocol support

Standards based HTTP Protocol access library.

Ref: https://datatracker.ietf.org/doc/html/rfc7231

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHelper

func NewHelper() *helper

func NewHttpHeadersBuilder

func NewHttpHeadersBuilder() *httpHeadersBuilder

func NewHttpReponseCode

func NewHttpReponseCode(status HttpStatus) *httpResponse

Produce an HTTP response, code only, no headers/body

func NewHttpRequestBodyBuilder

func NewHttpRequestBodyBuilder() *httpRequestBodyBuilder

func NewHttpRequestBodyBuilderFromRequest

func NewHttpRequestBodyBuilderFromRequest(request *gohttp.Request) *httpRequestBodyBuilder

NewHttpRequestBodyBuilderFromRequest creates a new HttpRequestBodyBuilder from an http.Request It automatically parses form data if needed and populates the body with PostForm values

func NewHttpRequestBuilder

func NewHttpRequestBuilder(method HttpRequestMethod, url string) *httpRequestBuilder

func NewHttpResponseBuilder

func NewHttpResponseBuilder() *httpResponseBuilder

func NewHttpResponseError

func NewHttpResponseError(status HttpStatus) *httpResponse

Produce an HTTP error response by HTTP status code only

func NewHttpResponseErrorJson

func NewHttpResponseErrorJson(status HttpStatus, message string) *httpResponse

Produce an ERROR HTTP response with JSON message body and standard headers

func NewHttpResponseObject

func NewHttpResponseObject(object *obj.Object, uri string) *httpResponse

Produce an HTTP response from an Object (200 OK)

func NewHttpResponseObjectCacheable

func NewHttpResponseObjectCacheable(object *obj.Object, uri string, maxAgeSeconds int) *httpResponse

Produce an HTTP response from an Object (200 OK)

func NewHttpResponseOk

func NewHttpResponseOk(body *string, contentType string) *httpResponse

Produce an OK HTTP response with standard headers

func NewHttpResponseRedirect

func NewHttpResponseRedirect(URL string) *httpResponse

Produce an HTTP redirect (TEMPORARY) response to the supplied URL

func NewHttpResponseSimpleJson

func NewHttpResponseSimpleJson(status HttpStatus) *httpResponse

Produce an HTTP response, code and default status text, JSON format

func NewHttpResponseStandard

func NewHttpResponseStandard(status HttpStatus, body *string, contentType string) *httpResponse

Produce an HTTP response with standard headers

func NewHttpResponseWithHeaders

func NewHttpResponseWithHeaders(status HttpStatus, body *string, headers HttpHeadersIfc) *httpResponse

Produce an HTTP response with custom headers

Types

type HelperIfc

type HelperIfc interface {
	// Payload Helpers
	SingularizePostData(bodyData *httpRequestBody) map[string]string
	GetMimetype(uri string) string
}

func GetHelper

func GetHelper() HelperIfc

Get our singleton

type HttpClient

type HttpClient struct {
	// Embedded struct(s)
	*cfg.Configurable
	*startable.Startable
	// contains filtered or unexported fields
}

Exported to support embedding

func NewHttpClient

func NewHttpClient() *HttpClient

func (*HttpClient) GetRequestResponse

func (r *HttpClient) GetRequestResponse(httpRequest HttpRequestIfc) (*httpResponse, error)

Initialize a request/client, fire it off, get the response, and transform it back to httpResponse

func (*HttpClient) Start

func (r *HttpClient) Start() error

type HttpClientIfc

type HttpClientIfc interface {
	// Embedded interface(s)
	cfg.ConfigurableIfc
	startable.StartableIfc

	// Our own interface
	GetRequestResponse(request HttpRequestIfc) (*httpResponse, error)
}

type HttpHeadersBuilderIfc

type HttpHeadersBuilderIfc interface {
	Set(name string, values ...string) *httpHeadersBuilder
	Append(name string, values ...string) *httpHeadersBuilder
	Merge(headers HttpHeadersIfc) *httpHeadersBuilder
	Override(headers HttpHeadersIfc) *httpHeadersBuilder
	GetHttpHeaders() *httpHeaders
}

type HttpHeadersIfc

type HttpHeadersIfc interface {
	Has(name string) bool
	GetNames() *[]string
	IsEmpty() bool
	Get(name string) *[]string
	ToMap() *httpHeadersData
	Size() int
	GetBuilder() *httpHeadersBuilder
}

type HttpRequestBodyBuilderIfc

type HttpRequestBodyBuilderIfc interface {
	Set(name string, values ...string) *httpRequestBodyBuilder
	Merge(requestBody HttpRequestBodyIfc) *httpRequestBodyBuilder
	GetHttpRequestBody() *httpRequestBody
}

type HttpRequestBodyIfc

type HttpRequestBodyIfc interface {
	Has(name string) bool
	GetNames() *[]string
	IsEmpty() bool
	Get(name string) *[]string
	Size() int
}

type HttpRequestBuilderIfc

type HttpRequestBuilderIfc interface {
	// URL bits
	SetQueryString(queryString string) *httpRequestBuilder
	SetQueryParameters(params metadata.MetadataIfc) *httpRequestBuilder

	// Body Bits
	SetBody(body *string) *httpRequestBuilder
	SetBodyData(bodyData *httpRequestBody) *httpRequestBuilder

	// Headers
	SetHeaders(headers HttpHeadersIfc) *httpRequestBuilder

	// Build
	GetHttpRequest() *httpRequest
}

Http Request public interface

type HttpRequestIfc

type HttpRequestIfc interface {
	GetHost() string
	GetScheme() string
	GetURL() string
	GetURI() string
	GetMethod() HttpRequestMethod
	GetQueryString() string
	GetQueryParameters() metadata.MetadataIfc
	GetPathParameters() metadata.MetadataIfc
	SetPathParameters(params metadata.MetadataIfc)
	GetBody() *string
	GetBodyData() *httpRequestBody
	GetHeaders() *httpHeaders
	GetBuilder() *httpRequestBuilder
}

type HttpRequestMethod

type HttpRequestMethod int
const (
	METHOD_UNKNOWN HttpRequestMethod = iota
	METHOD_GET
	METHOD_POST
	METHOD_DELETE
	METHOD_PATCH
	METHOD_PUT
	METHOD_HEAD
	METHOD_OPTIONS
)

func HttpRequestMethodFromString

func HttpRequestMethodFromString(httpRequestMethod string) HttpRequestMethod

func (HttpRequestMethod) IsIdempotent

func (r HttpRequestMethod) IsIdempotent() bool

Quick check if the current request is expected to be idempotent in implementation

func (HttpRequestMethod) ToString

func (r HttpRequestMethod) ToString() string

type HttpRequestMethodIfc

type HttpRequestMethodIfc interface {
	ToString() string
	IsIdempotent() bool
}

type HttpResponseBuilderIfc

type HttpResponseBuilderIfc interface {
	SetBinBody(body *[]byte) *httpResponseBuilder
	SetBody(body *string) *httpResponseBuilder
	SetStatus(status HttpStatus) *httpResponseBuilder
	SetProtocolVersion(version ver.VersionIfc) *httpResponseBuilder
	SetHeaders(headers HttpHeadersIfc) *httpResponseBuilder
	GetHttpResponse() *httpResponse
}

type HttpResponseIfc

type HttpResponseIfc interface {
	// Body supports any media type, text or binary, so []byte is the common storage structure
	GetBinBody() *[]byte
	// Some Body reponses might be text, so we support conversion between []byte and string
	GetBody() *string
	// Status is a code, but only specific, standards based statuses are supported
	GetStatus() HttpStatus
	GetProtocolVersion() ver.VersionIfc
	GetHeaders() HttpHeadersIfc
	GetBuilder() *httpResponseBuilder
}

HTTP Response public interface

func NewHttpResponseRedirectPermanent

func NewHttpResponseRedirectPermanent(URL string) HttpResponseIfc

Produce an HTTP redirect (PERMANENT) response to the supplied URL

type HttpStatus

type HttpStatus int
const (
	STATUS_UNKNOWN HttpStatus = iota
	STATUS_CONTINUE
	STATUS_SWITCHING_PROTOCOLS
	STATUS_OK
	STATUS_CREATED
	STATUS_ACCEPTED
	STATUS_NON_AUTHORITATIVE_INFORMATION
	STATUS_NO_CONTENT
	STATUS_RESET_CONTENT
	STATUS_PARTIAL_CONTENT
	STATUS_MULTIPLE_CHOICES
	STATUS_MOVED_PERMANENTLY
	STATUS_FOUND
	STATUS_SEE_OTHER
	STATUS_NOT_MODIFIED
	STATUS_USE_PROXY
	STATUS_TEMPORARY_REDIRECT
	STATUS_BAD_REQUEST
	STATUS_UNAUTHORIZED
	STATUS_FORBIDDEN
	STATUS_NOT_FOUND
	STATUS_METHOD_NOT_ALLOWED
	STATUS_NOT_ACCEPTABLE
	STATUS_PROXY_AUTHENTICATION_REQUIRED
	STATUS_REQUEST_TIMEOUT
	STATUS_CONFLICT
	STATUS_GONE
	STATUS_LENGTH_REQUIRED
	STATUS_PRECONDITION_FAILED
	STATUS_REQUEST_ENTITY_TOO_LARGE
	STATUS_REQUEST_URI_TOO_LONG
	STATUS_UNSUPPORTED_MEDIA_TYPE
	STATUS_REQUESTED_RANGE_NOT_SATISFIABLE
	STATUS_EXPECTATION_FAILED
	STATUS_INTERNAL_SERVER_ERROR
	STATUS_NOT_IMPLEMENTED
	STATUS_BAD_GATEWAY
	STATUS_SERVICE_UNAVAILABLE
	STATUS_GATEWAY_TIMEOUT
	STATUS_HTTP_VERSION_NOT_SUPPORTED
)

func HttpStatusFromCode

func HttpStatusFromCode(httpStatusCode int) HttpStatus

func (HttpStatus) GetHttpStatusCode

func (r HttpStatus) GetHttpStatusCode() int

func (HttpStatus) IsStatus1xx

func (r HttpStatus) IsStatus1xx() bool

Is the supplied HttpStatus a 1xx?

func (HttpStatus) IsStatus2xx

func (r HttpStatus) IsStatus2xx() bool

Is the supplied HttpStatus a 2xx?

func (HttpStatus) IsStatus3xx

func (r HttpStatus) IsStatus3xx() bool

Is the supplied HttpStatus a 3xx?

func (HttpStatus) IsStatus4xx

func (r HttpStatus) IsStatus4xx() bool

Is the supplied HttpStatus a 4xx?

func (HttpStatus) IsStatus5xx

func (r HttpStatus) IsStatus5xx() bool

Is the supplied HttpStatus a 5xx?

func (HttpStatus) ToString

func (r HttpStatus) ToString() string

Jump to

Keyboard shortcuts

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