Documentation ¶
Index ¶
- func CheckAuthFlag(w http.ResponseWriter, r *http.Request, expectedKey *flagutil.Password) bool
- func CheckBasicAuth(w http.ResponseWriter, r *http.Request) bool
- func EnableCORS(w http.ResponseWriter, _ *http.Request)
- func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...any)
- func GetPathPrefix() string
- func GetQuotedRemoteAddr(r *http.Request) string
- func GetRequestURI(r *http.Request) string
- func IsTLS(idx int) bool
- func LogError(req *http.Request, errStr string)
- func PrometheusErrorResponse(statusCode int, err error) string
- func Redirect(w http.ResponseWriter, url string)
- func SendPrometheusError(w http.ResponseWriter, r *http.Request, err error)
- func Serve(addrs []string, useProxyProtocol *flagutil.ArrayBool, rh RequestHandler)
- func Stop(addrs []string) error
- func StreamPrometheusErrorResponse(qw422016 *qt422016.Writer, statusCode int, err error)
- func WriteAPIHelp(w io.Writer, pathList [][2]string)
- func WritePrometheusErrorResponse(qq422016 qtio422016.Writer, statusCode int, err error)
- type ErrorWithStatusCode
- type Path
- type RequestHandler
- type UserReadableError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAuthFlag ¶
CheckAuthFlag checks whether the given authKey is set and valid
Falls back to checkBasicAuth if authKey is not set
func CheckBasicAuth ¶
func CheckBasicAuth(w http.ResponseWriter, r *http.Request) bool
CheckBasicAuth validates credentials provided in request if httpAuth.* flags are set returns true if credentials are valid or httpAuth.* flags are not set
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 GetQuotedRemoteAddr ¶
GetQuotedRemoteAddr returns quoted remote address.
func GetRequestURI ¶
GetRequestURI returns requestURI for r.
func PrometheusErrorResponse ¶
func Redirect ¶
func Redirect(w http.ResponseWriter, url string)
Redirect redirects to the given url.
func SendPrometheusError ¶
func SendPrometheusError(w http.ResponseWriter, r *http.Request, err error)
SendPrometheusError sends err to w in Prometheus querying API response format.
See https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview for more details
func Serve ¶
func Serve(addrs []string, useProxyProtocol *flagutil.ArrayBool, rh RequestHandler)
Serve starts an http server on the given addrs with the given optional rh.
By default all the responses are transparently compressed, since egress traffic is usually expensive.
The compression can be disabled by specifying -http.disableResponseCompression command-line flag.
If useProxyProtocol is set to true for the corresponding addr, then the incoming connections are accepted via proxy protocol. See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
func WriteAPIHelp ¶
WriteAPIHelp writes pathList to w in HTML format.
func WritePrometheusErrorResponse ¶
func WritePrometheusErrorResponse(qq422016 qtio422016.Writer, statusCode int, err error)
Types ¶
type ErrorWithStatusCode ¶
ErrorWithStatusCode is error with HTTP status code.
The given StatusCode is sent to client when the error is passed to Errorf.
func (*ErrorWithStatusCode) Error ¶
func (e *ErrorWithStatusCode) Error() string
Error implements error interface.
func (*ErrorWithStatusCode) Unwrap ¶
func (e *ErrorWithStatusCode) Unwrap() error
Unwrap returns e.Err.
This is used by standard errors package. See https://golang.org/pkg/errors
type Path ¶
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.
type UserReadableError ¶
type UserReadableError struct { // Err is the error which needs to be returned to the user. Err error }
UserReadableError is a type of error which supposed to be returned to the user without additional context.
func (*UserReadableError) Error ¶
func (ure *UserReadableError) Error() string
Error satisfies Error interface
func (*UserReadableError) Unwrap ¶
func (ure *UserReadableError) Unwrap() error
Unwrap returns ure.Err.
This is used by standard errors package. See https://golang.org/pkg/errors