httpserver

package
v1.40.1-cluster Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 23 Imported by: 13

Documentation

Index

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 GetQuotedRemoteAddr added in v1.39.3

func GetQuotedRemoteAddr(r *http.Request) string

GetQuotedRemoteAddr returns quoted remote address.

func IsTLS added in v1.34.6

func IsTLS() bool

IsTLS indicates is tls enabled or not

func RegisterSecretFlag added in v1.34.0

func RegisterSecretFlag(flagName string)

RegisterSecretFlag registers flagName as secret.

This function must be called before starting httpserver. It cannot be called from concurrent goroutines.

Secret flags aren't exported at `/metrics` page.

func Serve

func Serve(addr string, rh RequestHandler)

Serve starts an http server on the given addr with the given 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 Stop

func Stop(addr string) error

Stop stops the http server on the given addr, which has been started via Serve func.

func WritePrometheusMetrics added in v1.32.8

func WritePrometheusMetrics(w io.Writer)

WritePrometheusMetrics writes all the registered metrics to w in Prometheus exposition format.

Types

type ErrorWithStatusCode added in v1.27.0

type ErrorWithStatusCode struct {
	Err        error
	StatusCode int
}

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

type Path struct {
	Prefix    string
	AuthToken string
	Suffix    string
}

Path contains the following path structure: /{prefix}/{authToken}/{suffix}

It is compatible with SaaS version.

func ParsePath added in v1.64.0

func ParsePath(path string) (*Path, error)

ParsePath parses the given path.

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.

Jump to

Keyboard shortcuts

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