http

package
v0.0.0-...-949823d Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: Apache-2.0 Imports: 74 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APITokenAuthMiddleware

func APITokenAuthMiddleware(token string) func(next http.Handler) http.Handler

APITokenAuthMiddleware enforces authentication using the dapr-api-token header.

func CleanPathMiddleware

func CleanPathMiddleware(next http.Handler) http.Handler

CleanPathMiddleware middleware will clean out double slash mistakes from a user's request path. For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1

This is a modified version of the code from https://github.com/go-chi/chi/blob/v5.0.8/middleware/clean_path.go Original code Copyright (c) 2015-present Peter Kieltyka (https://github.com/pkieltyka), Google Inc. Original code license: MIT: https://github.com/go-chi/chi/blob/v5.0.8/LICENSE

func ConvertEventToBytes

func ConvertEventToBytes(event interface{}, contentType string) ([]byte, error)

func GetStatusCodeFromMetadata

func GetStatusCodeFromMetadata(metadata map[string]string) int

GetStatusCodeFromMetadata extracts the http status code from the metadata if it exists.

func MaxBodySizeMiddleware

func MaxBodySizeMiddleware(maxSize int64) func(next http.Handler) http.Handler

MaxBodySizeMiddleware limits the body size to the given size (in bytes).

func StripSlashesMiddleware

func StripSlashesMiddleware(next http.Handler) http.Handler

StripSlashesMiddleware is a middleware that will match request paths with a trailing slash, strip it from the path and continue routing through the mux, if a route matches, then it will serve the handler.

This is a modified version of the code from https://github.com/go-chi/chi/blob/v5.0.8/middleware/strip.go It does not remove the trailing slash if it matches a route already. Original code Copyright (c) 2015-present Peter Kieltyka (https://github.com/pkieltyka), Google Inc. Original code license: MIT: https://github.com/go-chi/chi/blob/v5.0.8/LICENSE

func UniversalHTTPHandler

func UniversalHTTPHandler[T proto.Message, U proto.Message](
	handler func(ctx context.Context, in T) (U, error),
	opts UniversalHTTPHandlerOpts[T, U],
) http.HandlerFunc

UniversalHTTPHandler wraps a Universal API method into a HTTP handler.

Types

type API

type API interface {
	APIEndpoints() []endpoints.Endpoint
	PublicEndpoints() []endpoints.Endpoint
}

API returns a list of HTTP endpoints for Dapr.

func NewAPI

func NewAPI(opts APIOpts) API

NewAPI returns a new API.

type APIOpts

type APIOpts struct {
	Universal             *universal.Universal
	Channels              *channels.Channels
	DirectMessaging       invokev1.DirectMessaging
	PubSubAdapter         runtimePubsub.Adapter
	Outbox                outbox.Outbox
	SendToOutputBindingFn func(ctx context.Context, name string, req *bindings.InvokeRequest) (*bindings.InvokeResponse, error)
	TracingSpec           config.TracingSpec
	MetricSpec            *config.MetricSpec
	MaxRequestBodySize    int64 // In bytes
	Healthz               healthz.Healthz
	OutboundHealthz       healthz.Healthz
}

APIOpts contains the options for NewAPI.

type BulkGetRequest

type BulkGetRequest struct {
	Metadata    map[string]string `json:"metadata"`
	Keys        []string          `json:"keys"`
	Parallelism int               `json:"parallelism"`
}

BulkGetRequest is the request object to get a list of values for multiple keys from a state store.

type BulkGetResponse

type BulkGetResponse struct {
	Key      string            `json:"key"`
	Data     json.RawMessage   `json:"data,omitempty"`
	ETag     *string           `json:"etag,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
	Error    string            `json:"error,omitempty"`
}

BulkGetResponse is the response object for a state bulk get operation.

type BulkPublishResponse

type BulkPublishResponse struct {
	FailedEntries []BulkPublishResponseFailedEntry `json:"failedEntries"`
	ErrorCode     string                           `json:"errorCode,omitempty"`
}

BulkPublishResponse is the response for bulk publishing events

type BulkPublishResponseFailedEntry

type BulkPublishResponseFailedEntry struct {
	EntryId string `json:"entryId"` //nolint:stylecheck
	Error   string `json:"error,omitempty"`
}

BulkPublishResponseEntry is an object representing a single entry in bulk publish response

type ErrorResponse

type ErrorResponse struct {
	ErrorCode string `json:"errorCode"`
	Message   string `json:"message"`
}

ErrorResponse is an HTTP response message sent back to calling clients by the Dapr Runtime HTTP API.

func NewErrorResponse

func NewErrorResponse(errorCode, message string) ErrorResponse

NewErrorResponse returns a new ErrorResponse.

func (ErrorResponse) JSONErrorValue

func (e ErrorResponse) JSONErrorValue() []byte

JSONErrorValue implements errorResponseValue.

type NewServerOpts

type NewServerOpts struct {
	API         API
	Config      ServerConfig
	TracingSpec config.TracingSpec
	MetricSpec  config.MetricSpec
	Middleware  middleware.HTTP
	APISpec     config.APISpec
}

NewServerOpts are the options for NewServer.

type OutputBindingRequest

type OutputBindingRequest struct {
	Metadata  map[string]string `json:"metadata"`
	Data      interface{}       `json:"data"`
	Operation string            `json:"operation"`
}

OutputBindingRequest is the request object to invoke an output binding.

type QueryItem

type QueryItem struct {
	Key   string          `json:"key"`
	Data  json.RawMessage `json:"data"`
	ETag  *string         `json:"etag,omitempty"`
	Error string          `json:"error,omitempty"`
}

QueryItem is an object representing a single entry in query results.

type QueryResponse

type QueryResponse struct {
	Results  []QueryItem       `json:"results"`
	Token    string            `json:"token,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

QueryResponse is the response object for querying state.

type Server

type Server interface {
	io.Closer
	StartNonBlocking() error
}

Server is an interface for the Dapr HTTP server.

func NewServer

func NewServer(opts NewServerOpts) Server

NewServer returns a new HTTP server.

type ServerConfig

type ServerConfig struct {
	AppID                   string
	HostAddress             string
	Port                    int
	APIListenAddresses      []string
	PublicPort              *int
	PublicListenAddress     string
	ProfilePort             int
	AllowedOrigins          string
	EnableProfiling         bool
	MaxRequestBodySize      int // In bytes
	UnixDomainSocket        string
	ReadBufferSize          int
	EnableAPILogging        bool
	APILoggingObfuscateURLs bool
	APILogHealthChecks      bool
}

ServerConfig holds config values for an HTTP server.

type UniversalHTTPHandlerOpts

type UniversalHTTPHandlerOpts[T proto.Message, U proto.Message] struct {
	// This modifier allows modifying the input proto object before the handler is called. This property is optional.
	// The input proto object contantains all properties parsed from the request's body (for non-GET requests), and this modifier can alter it for example with properties from the URL (to make APIs RESTful).
	// The modifier should return the modified object.
	InModifier func(r *http.Request, in T) (T, error)

	// This modifier allows modifying the output proto object before the response is sent to the client. This property is optional.
	// This is primarily meant to ensure that existing APIs can be migrated to Universal ones while preserving the same response in case of small differences.
	// The response could be a proto object (which will be serialized with protojson) or any other object (serialized with the standard JSON package). If the response is nil, a 204 (no content) response is sent to the client, with no data in the body.
	// NOTE: Newly-implemented APIs should ensure that on the HTTP endpoint the response matches the protos to offer a consistent experience, and should NOT modify the output before it's sent to the client.
	OutModifier func(out U) (any, error)

	// Status code to return on successful responses.
	// Defaults to 200 (OK) if unset.
	SuccessStatusCode int

	// If true, skips parsing the body of the request in the input proto.
	SkipInputBody bool

	// When true, unpopulated fields in proto responses (i.e. fields whose value is the zero one) are included in the response too.
	// Defaults to false.
	ProtoResponseEmitUnpopulated bool
}

Object containing options for the UniversalHTTPHandler method.

type UniversalHTTPRawResponse

type UniversalHTTPRawResponse struct {
	// Body of the response.
	Body []byte
	// Optional value for the Content-Type header to send.
	ContentType string
	// Optional status code; if empty, uses the default SuccessStatusCode.
	StatusCode int
}

Contains a pre-serialized response as well as its content type. An OutModifier can return this object if it needs to serialize the response itself.

type UnsubscribeConfigurationResponse

type UnsubscribeConfigurationResponse struct {
	Ok      bool   `json:"ok,omitempty"      protobuf:"varint,1,opt,name=ok,proto3"`
	Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message,proto3"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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