Documentation ¶
Index ¶
- func DisableResponseCompression(w http.ResponseWriter)
- func EnableCORS(w http.ResponseWriter, _ *http.Request)
- func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...interface{})
- func GetPathPrefix() string
- func GetQuotedRemoteAddr(r *http.Request) string
- func GetRequestURI(r *http.Request) string
- func IsTLS() bool
- func RedirectPermanent(w http.ResponseWriter, url string)
- func Serve(addr string, rh RequestHandler)
- func Stop(addr string) error
- func WriteAPIHelp(w io.Writer, pathList [][2]string)
- func WritePrometheusMetrics(w io.Writer)
- type ErrorWithStatusCode
- type Path
- type RequestHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableResponseCompression ¶
func DisableResponseCompression(w http.ResponseWriter)
DisableResponseCompression disables response compression on w.
The function must be called before the first w.Write* call.
func EnableCORS ¶
func EnableCORS(w http.ResponseWriter, _ *http.Request)
EnableCORS enables https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS on the response.
func Errorf ¶
func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...interface{})
Errorf writes formatted error message to w and to logger.
func GetPathPrefix ¶ added in v1.50.0
func GetPathPrefix() string
GetPathPrefix - returns http server path prefix.
func GetQuotedRemoteAddr ¶ added in v1.39.3
GetQuotedRemoteAddr returns quoted remote address.
func GetRequestURI ¶ added in v1.63.0
GetRequestURI returns requestURI for r.
func RedirectPermanent ¶ added in v1.79.2
func RedirectPermanent(w http.ResponseWriter, url string)
RedirectPermanent redirects to the given url using 301 status code.
func Serve ¶
func Serve(addr string, rh RequestHandler)
Serve starts an http server on the given addr with the given optional rh.
By default all the responses are transparently compressed, since Google charges a lot for the egress traffic. The compression may be disabled by calling DisableResponseCompression before writing the first byte to w.
The compression is also disabled if -http.disableResponseCompression flag is set.
func WriteAPIHelp ¶ added in v1.59.0
WriteAPIHelp writes pathList to w in HTML format.
func WritePrometheusMetrics ¶ added in v1.32.8
WritePrometheusMetrics writes all the registered metrics to w in Prometheus exposition format.
Types ¶
type ErrorWithStatusCode ¶ added in v1.27.0
ErrorWithStatusCode is error with HTTP status code.
The given StatusCode is sent to client when the error is passed to Errorf.
func (*ErrorWithStatusCode) Error ¶ added in v1.27.0
func (e *ErrorWithStatusCode) Error() string
Error implements error interface.
func (*ErrorWithStatusCode) Unwrap ¶ added in v1.37.4
func (e *ErrorWithStatusCode) Unwrap() error
Unwrap returns e.Err.
This is used by standard errors package. See https://golang.org/pkg/errors
type Path ¶ added in v1.64.0
Path contains the following path structure: /{prefix}/{authToken}/{suffix}
It is compatible with SaaS version.
type RequestHandler ¶
type RequestHandler func(w http.ResponseWriter, r *http.Request) bool
RequestHandler must serve the given request r and write response to w.
RequestHandler must return true if the request has been served (successfully or not).
RequestHandler must return false if it cannot serve the given request. In such cases the caller must serve the request.