Documentation ¶
Overview ¶
Package aghhttp provides some common methods to work with HTTP.
Index ¶
- Constants
- func Error(r *http.Request, w http.ResponseWriter, code int, format string, args ...any)
- func OK(w http.ResponseWriter)
- func UserAgent() (ua string)
- func WriteJSONResponse(w http.ResponseWriter, r *http.Request, resp any) (err error)
- func WriteJSONResponseCode(w http.ResponseWriter, r *http.Request, code int, resp any) (err error)
- func WriteTextPlainDeprecated(w http.ResponseWriter, r *http.Request) (isPlainText bool)
- type RegisterFunc
Constants ¶
const ( SchemeHTTP = "http" SchemeHTTPS = "https" )
HTTP scheme constants.
const ( HdrNameAcceptEncoding = "Accept-Encoding" HdrNameAccessControlAllowOrigin = "Access-Control-Allow-Origin" HdrNameContentEncoding = "Content-Encoding" HdrNameContentType = "Content-Type" HdrNameServer = "Server" HdrNameTrailer = "Trailer" HdrNameUserAgent = "User-Agent" )
HTTP header name constants.
TODO(a.garipov): Remove unused.
const ( HdrValApplicationJSON = "application/json" HdrValTextPlain = "text/plain" )
HTTP header value constants.
Variables ¶
This section is empty.
Functions ¶
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
WriteJSONResponse sets the content-type header in w.Header() to "application/json", writes a header with a "200 OK" status, encodes resp to w, calls Error on any returned error, and returns it as well.
func WriteJSONResponseCode ¶ added in v0.107.17
WriteJSONResponseCode is like WriteJSONResponse but adds the ability to redefine the status code.
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.