api

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: GPL-3.0 Imports: 15 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.

func WriteSSZResponse

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

Types

type BeaconError

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

type ContentType

type ContentType int
const (
	ContentTypeUnknown ContentType = iota
	ContentTypeJSON
	ContentTypeYAML
	ContentTypeSSZ
)

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 {
	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. All http-level concerns should be handled in this package, with the "namespaces" (eth/checkpointz) handling all business logic and dealing with concrete types.

func NewHandler

func NewHandler(log logrus.FieldLogger, beac beacon.FinalityProvider, config *beacon.Config) *Handler

func (*Handler) Register

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

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 string)

func (Metrics) ObserveResponse

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

Jump to

Keyboard shortcuts

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