web

package
v0.0.0-...-edcd610 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Apache v2 license

* Copyright (C) <2019> Intel Corporation * * SPDX-License-Identifier: Apache-2.0

Apache v2 license

* Copyright (C) <2019> Intel Corporation * * SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const KeyValues ctxKey = 1

KeyValues is how request values or stored/retrieved.

Variables

This section is empty.

Functions

func EntityTooLargeError

func EntityTooLargeError() error

EntityTooLargeError occurs when the input data is too large.

func Error

func Error(ctx context.Context, writer http.ResponseWriter, err error)

Error handles all error responses for the API.

func InvalidIDError

func InvalidIDError() error

InvalidIDError occurs when an ID is not in a valid form.

func InvalidInputError

func InvalidInputError(err error) error

InvalidInputError occurs when external data validation fails, giving a suberror.

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if an error is an instance of a NotFoundError, or a wrapped instance of a NotFoundError.

func NotAuthorizedError

func NotAuthorizedError() error

NotAuthorizedError occurs when the call is not authorized.

func NotFoundError

func NotFoundError() error

func Respond

func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)

Respond sends JSON to the client. If code is StatusNoContent, v is expected to be nil.

func RespondError

func RespondError(ctx context.Context, writer http.ResponseWriter, err error, code int)

RespondError sends JSON describing the error

func RespondHTML

func RespondHTML(writer http.ResponseWriter, title string, body string, code int)

RespondHTML sends HTML to the client. If code is StatusNoContent, body is expected to be nil.

func ValidationError

func ValidationError(msg string) error

ValidationError occurs when there are internal validation errors, giving a message.

Types

type CommonError

type CommonError struct {
	Code int
	// contains filtered or unexported fields
}

CommonError makes it easier to identify and handle common errors.

type ContextValues

type ContextValues struct {
	TraceID    string
	Method     string
	RequestURI string
}

ContextValues used during log

type Handler

Handler is a type that handles a http request

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP interface is implemented by Handler

type JSONError

type JSONError struct {
	// The error message
	// in: body
	Error string `json:"error"`
}

JSONError is the response for errors that occur within the API. swagger:response internalError

type Middleware

type Middleware func(Handler) Handler

A Middleware is a type that wraps a handler to remove boilerplate or other concerns not direct to any given Handler.

Jump to

Keyboard shortcuts

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