api

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoesAccept

func DoesAccept(accepts []ContentType, input ContentType) bool

func ValidateContentType

func ValidateContentType(contentType ContentType, accepting []ContentType) error

func WriteContentAwareResponse

func WriteContentAwareResponse(w http.ResponseWriter, data []byte, contentType ContentType) error

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, msg string, statusCode int) error

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, data []byte) error

WriteJSONResponse writes a JSON response to the given writer.

Types

type ContentType

type ContentType int
const (
	ContentTypeUnknown ContentType = iota
	ContentTypeJSON
)

func DeriveContentType

func DeriveContentType(accept string) ContentType

func NewContentTypeFromRequest

func NewContentTypeFromRequest(r *http.Request) ContentType

func (ContentType) String

func (c ContentType) String() string

type ContentTypeResolver

type ContentTypeResolver func() ([]byte, error)

type ContentTypeResolvers

type ContentTypeResolvers map[ContentType]ContentTypeResolver

type HTTPResponse

type HTTPResponse struct {

	//nolint:tagliatelle // spec requires this field to be named "status_code"
	StatusCode int               `json:"status_code"`
	Headers    map[string]string `json:"headers"`
	ExtraData  map[string]interface{}
	// contains filtered or unexported fields
}

func NewBadRequestResponse

func NewBadRequestResponse(resolvers ContentTypeResolvers) *HTTPResponse

func NewInternalServerErrorResponse

func NewInternalServerErrorResponse(resolvers ContentTypeResolvers) *HTTPResponse

func NewSuccessResponse

func NewSuccessResponse(resolvers ContentTypeResolvers) *HTTPResponse

func NewUnsupportedMediaTypeResponse

func NewUnsupportedMediaTypeResponse(resolvers ContentTypeResolvers) *HTTPResponse

func (*HTTPResponse) AddExtraData

func (r *HTTPResponse) AddExtraData(key string, value interface{})

func (HTTPResponse) MarshalAs

func (r HTTPResponse) MarshalAs(contentType ContentType) ([]byte, error)

func (HTTPResponse) SetCacheControl

func (r HTTPResponse) SetCacheControl(v string)

func (HTTPResponse) SetEtag

func (r HTTPResponse) SetEtag(etag string)

type Handler

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

Handler is an API handler that is responsible for negotiating with a HTTP api.

func NewHandler

func NewHandler(log logrus.FieldLogger, conf *exec.Config) *Handler

func (*Handler) Register

func (h *Handler) Register(ctx context.Context, router *httprouter.Router) error

func (*Handler) Start added in v0.0.5

func (h *Handler) Start(ctx context.Context)

type JSONRequestBody

type JSONRequestBody struct {
	ID     int                `json:"id"`
	Method string             `json:"method"`
	Params []*json.RawMessage `json:"params"`
}

type Metrics

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

func NewMetrics

func NewMetrics(namespace string) Metrics

func (Metrics) ObserveRequest

func (m Metrics) ObserveRequest(method, path, executionMethod string)

func (Metrics) ObserveResponse

func (m Metrics) ObserveResponse(method, path, code, encoding, executionMethod string, duration time.Duration)

type StubbiesError

type StubbiesError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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