http

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is used to power HTTP endpoint wrappers to the VTAdminServer interface.

func NewAPI

func NewAPI(server vtadminpb.VTAdminServer) *API

NewAPI returns an HTTP API backed by the given VTAdminServer implementation.

func (*API) Adapt

func (api *API) Adapt(handler VTAdminHandler) http.HandlerFunc

Adapt converts a VTAdminHandler into an http.HandlerFunc. It deals with wrapping the request in a wrapper for some convenience functions and starts a new context, after extracting any potential spans that were set by an upstream middleware in the request context.

type JSONResponse

type JSONResponse struct {
	Result interface{} `json:"result,omitempty"`
	Error  *errorBody  `json:"error,omitempty"`
	Ok     bool        `json:"ok"`
	// contains filtered or unexported fields
}

JSONResponse represents a generic response object.

func GetGates

func GetGates(ctx context.Context, r Request, api *API) *JSONResponse

GetGates implements the http wrapper for /gates[?cluster=[&cluster=]].

func GetTablet

func GetTablet(ctx context.Context, r Request, api *API) *JSONResponse

GetTablet implements the http wrapper for /tablet/{tablet}[?cluster=[&cluster=]].

func GetTablets

func GetTablets(ctx context.Context, r Request, api *API) *JSONResponse

GetTablets implements the http wrapper for /tablets[?cluster=[&cluster=]].

func NewJSONResponse

func NewJSONResponse(value interface{}, err error) *JSONResponse

NewJSONResponse returns a JSONResponse for the given result and error. If err is non-nil, and implements errors.TypedError, the HTTP status code and message are provided by the error. If not, the code and message fallback to 500 unknown.

func (*JSONResponse) WithHTTPStatus

func (r *JSONResponse) WithHTTPStatus(code int) *JSONResponse

WithHTTPStatus forces a response to be used for the JSONResponse.

func (*JSONResponse) Write

func (r *JSONResponse) Write(w http.ResponseWriter)

Write marshals a JSONResponse into the http response.

type Options

type Options struct {
	// CORSOrigins is the list of origins to allow via CORS. An empty or nil
	// slice disables CORS entirely.
	CORSOrigins []string
	// EnableTracing specifies whether to install a tracing middleware on the
	// API subrouter.
	EnableTracing bool
	// DisableCompression specifies whether to turn off gzip compression for API
	// endpoints. It is named as the negative (as opposed to EnableTracing) so
	// the zero value has compression enabled.
	DisableCompression bool
}

Options defines the set of configurations for an HTTP API server.

type Request

type Request struct{ *http.Request }

Request wraps an *http.Request to provide some convenience functions for accessing request data.

func (Request) Vars

func (r Request) Vars() map[string]string

Vars returns the route variables in a request, if any, as defined by gorilla/mux.

type VTAdminHandler

type VTAdminHandler func(ctx context.Context, r Request, api *API) *JSONResponse

VTAdminHandler is an HTTP endpoint handler that takes, via injection, everything needed to implement a JSON API response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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