aghhttp

package
v0.108.0-b.16 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package aghhttp provides some common methods to work with HTTP.

Index

Constants

View Source
const (
	SchemeHTTP  = "http"
	SchemeHTTPS = "https"
)

HTTP scheme constants.

View Source
const (
	HdrNameAcceptEncoding           = "Accept-Encoding"
	HdrNameAccessControlAllowOrigin = "Access-Control-Allow-Origin"
	HdrNameContentType              = "Content-Type"
	HdrNameContentEncoding          = "Content-Encoding"
	HdrNameServer                   = "Server"
	HdrNameTrailer                  = "Trailer"
	HdrNameUserAgent                = "User-Agent"
)

HTTP header name constants.

TODO(a.garipov): Remove unused.

View Source
const (
	HdrValApplicationJSON = "application/json"
	HdrValTextPlain       = "text/plain"
)

HTTP header value constants.

Variables

This section is empty.

Functions

func Error

func Error(r *http.Request, w http.ResponseWriter, code int, format string, args ...any)

Error writes formatted message to w and also logs it.

func OK

func OK(w http.ResponseWriter)

OK responds with word OK.

func UserAgent added in v0.107.14

func UserAgent() (ua string)

UserAgent returns the ID of the service as a User-Agent string. It can also be used as the value of the Server HTTP header.

func WriteJSONResponse added in v0.107.14

func WriteJSONResponse(w http.ResponseWriter, r *http.Request, resp any) (err error)

WriteJSONResponse sets the content-type header in w.Header() to "application/json", encodes resp to w, calls Error on any returned error, and returns it as well.

func WriteTextPlainDeprecated added in v0.107.14

func WriteTextPlainDeprecated(w http.ResponseWriter, r *http.Request) (isPlainText bool)

WriteTextPlainDeprecated responds to the request with a message about deprecation and removal of a plain-text API if the request is made with the "text/plain" content-type.

Types

type RegisterFunc added in v0.107.10

type RegisterFunc func(method, url string, handler http.HandlerFunc)

RegisterFunc is the function that sets the handler to handle the URL for the method.

TODO(e.burkov, a.garipov): Get rid of it.

Jump to

Keyboard shortcuts

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