request

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInternal

func IsInternal(r *http.Request) bool

IsInternal returns true if the request is internal.

func IsProxied

func IsProxied(r *http.Request) bool

IsProxied returns true if the request is from kubernetes.

func MethodNotAllowedHandler

func MethodNotAllowedHandler() http.HandlerFunc

MethodNotAllowedHandler returns a handler that returns a 405 response.

func NotFoundHandler

func NotFoundHandler() http.HandlerFunc

NotFoundHandler returns a handler that returns a 404 response.

func UnauthorizedHandler

func UnauthorizedHandler() http.HandlerFunc

UnauthorizedHandler returns a handler that returns a 401 response.

Types

type ClientWriter

type ClientWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ClientWriter is a wrapper around http.ResponseWriter that provides additional information. It is used to capture the status code and the number of bytes written. It also provides a way to determine if the header has been written.

func NewClientWriter

func NewClientWriter(w http.ResponseWriter) *ClientWriter

NewClientWriter creates a new ClientWriter.

func (*ClientWriter) BytesWritten

func (c *ClientWriter) BytesWritten() uint64

BytesWritten returns the number of bytes written.

func (*ClientWriter) IsHeaderWritten

func (c *ClientWriter) IsHeaderWritten() bool

IsHeaderWritten returns true if the header has been written.

func (*ClientWriter) SetContentType

func (c *ClientWriter) SetContentType(contentType string)

func (*ClientWriter) SetJsonContentType

func (c *ClientWriter) SetJsonContentType()

SetJsonContentType sets the content type to JSON.

func (*ClientWriter) SetStatus

func (c *ClientWriter) SetStatus(status int)

SetStatus sets the status code.

func (*ClientWriter) SetXmlContentType

func (c *ClientWriter) SetXmlContentType()

SetXmlContentType sets the content type to XML.

func (*ClientWriter) StatusCode

func (c *ClientWriter) StatusCode() int

StatusCode returns the status code.

func (*ClientWriter) Write

func (c *ClientWriter) Write(p []byte) (bytes int, err error)

Write writes the data to the connection as part of an HTTP reply.

func (*ClientWriter) WriteHeader

func (c *ClientWriter) WriteHeader(code int)

WriteHeader sends an HTTP response header with the provided status code.

type ContentType

type ContentType string

ContentType represents the content type of the request.

const (
	// ContentTypeJSON is the JSON content type. This is the default.
	ContentTypeJSON ContentType = "application/json"

	// ContentTypeXML is the XML content type.
	ContentTypeXML ContentType = "application/xml"

	// ContentTypeHTML is the HTML content type.
	ContentTypeHTML ContentType = "text/html"

	// ContentTypeText is the text content type.
	ContentTypeText ContentType = "text/plain"

	// ContentTypePng is the png content type.
	ContentTypePng ContentType = "image/png"
)

func (ContentType) IsIn

func (c ContentType) IsIn(contentTypes ...ContentType) bool

IsIn returns true if the ContentType is in the list of content types.

func (ContentType) String

func (c ContentType) String() string

String returns the string representation of the ContentType.

type Message

type Message struct {
	Message string `json:"message" xml:"message"`
}

Message represents a message response.

func NewMessage

func NewMessage(message string, args ...any) *Message

NewMessage creates a new Message.

type RateLimiter

type RateLimiter interface {
	// Allow returns true if the request is allowed.
	Allow(key string) bool
}

func NewRateLimiter

func NewRateLimiter() RateLimiter

Jump to

Keyboard shortcuts

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