http

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrometheusMiddleware

func PrometheusMiddleware(next http.Handler) http.Handler

func ValidateUserMiddleware

func ValidateUserMiddleware(next http.Handler) http.Handler

Types

type CatalogClient

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

CatalogClient is a client that queries the Catalog service.

func NewCatalogClient added in v0.1.1

func NewCatalogClient(url string) CatalogClient

NewCatalogClient returns a ready-to-use client for the QuickPizza catalog, service given its URL.

func (CatalogClient) Doughs

func (c CatalogClient) Doughs() ([]pizza.Dough, error)

func (CatalogClient) Ingredients

func (c CatalogClient) Ingredients(ingredientType string) ([]pizza.Ingredient, error)

func (CatalogClient) RecordRecommendation

func (c CatalogClient) RecordRecommendation(p pizza.Pizza) error

func (CatalogClient) Tools

func (c CatalogClient) Tools() ([]string, error)

func (CatalogClient) WithClient added in v0.1.1

func (c CatalogClient) WithClient(client *http.Client) CatalogClient

WithClient returns a CatalogClient that uses the specified http.Client, instead of http.DefaultClient.

func (CatalogClient) WithRequestContext

func (c CatalogClient) WithRequestContext(ctx context.Context) CatalogClient

WithRequestContext returns a copy of the CatalogClient that will use the supplied context. This context should come from a http.Request, and if provided, CatalogClient will: - Extract parent tracer and trace IDs from it and propagate it to the requests it makes. - Extract the QuickPizza user ID from it and propagate it as well.

type ContextLogger added in v0.2.0

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

func NewContextLogger added in v0.2.0

func NewContextLogger(parent slog.Handler) *ContextLogger

func (*ContextLogger) Enabled added in v0.2.0

func (c *ContextLogger) Enabled(ctx context.Context, level slog.Level) bool

func (*ContextLogger) Handle added in v0.2.0

func (c *ContextLogger) Handle(ctx context.Context, record slog.Record) error

func (*ContextLogger) WithAttrs added in v0.2.0

func (c *ContextLogger) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ContextLogger) WithGroup added in v0.2.0

func (c *ContextLogger) WithGroup(name string) slog.Handler

type CopyClient

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

CopyClient is a client that queries the Copy service.

func NewCopyClient added in v0.1.1

func NewCopyClient(url string) CopyClient

NewCopyClient is the Copy service equivalent of NewCatalogClient.

func (CopyClient) Adjectives

func (c CopyClient) Adjectives() ([]string, error)

func (CopyClient) Names

func (c CopyClient) Names() ([]string, error)

func (CopyClient) WithClient added in v0.1.1

func (c CopyClient) WithClient(client *http.Client) CopyClient

WithClient is the Copy service equivalent of CatalogClient.

func (CopyClient) WithRequestContext

func (c CopyClient) WithRequestContext(ctx context.Context) CopyClient

WithRequestContext is the Copy service equivalent of CatalogClient.

type PizzaRecommendation

type PizzaRecommendation struct {
	Pizza      pizza.Pizza `json:"pizza"`
	Calories   int         `json:"calories"`
	Vegetarian bool        `json:"vegetarian"`
}

PizzaRecommendation is the object returned by the /api/pizza endpoint.

type Server

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

Server is the object that handles HTTP requests and computes pizza recommendations. Routes are divided into serveral groups that can be instantiated independently as microservices, or all together as one single big service.

func NewServer

func NewServer() (*Server, error)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request)

func (*Server) WithCatalog

func (s *Server) WithCatalog(db *database.InMemoryDatabase) *Server

WithCatalog enables routes related to the ingredients, doughs, and tools. A database.InMemoryDatabase is required to enable this endpoint group. This database is safe to be used concurrently and thus may be shared with other endpoint groups.

func (*Server) WithConfig added in v0.3.0

func (s *Server) WithConfig(config map[string]string) *Server

WithConfig enables serving the config server.

func (*Server) WithCopy

func (s *Server) WithCopy(db *database.InMemoryDatabase) *Server

WithCopy enables copy (i.e. prose) related endpoints.

func (*Server) WithFrontend

func (s *Server) WithFrontend() *Server

WithFrontend enables serving the embedded Svelte frontend.

func (*Server) WithGateway

func (s *Server) WithGateway(catalogUrl, copyUrl, wsUrl, recommendationsUrl, configUrl string) *Server

WithGateway enables a gateway that routes external requests to the respective services. This endpoint should be typically enabled toget with WithFrontend on a microservices-based deployment. TODO: So far the gateway only handles a few endpoints.

func (*Server) WithInsecureTraceContext added in v0.1.1

func (s *Server) WithInsecureTraceContext() *Server

WithInsecureTraceContext configures the server to trust parent trace IDs arriving to public-facing endpoints. This will make traces generated by QuickPizza to be children of client-controlled trace IDs.

func (*Server) WithPrometheus

func (s *Server) WithPrometheus() *Server

WithPrometheus adds a /metrics endpoint and instrument subsequently enabled groups with general http-level metrics.

func (*Server) WithRecommendations

func (s *Server) WithRecommendations(catalogClient CatalogClient, copyClient CopyClient) *Server

WithRecommendations enables the recommendations endpoint in this Server. This endpoint is stateless and thus needs the URLs for the Catalog and Copy services.

func (*Server) WithTracing

func (s *Server) WithTracing(provider trace.TracerProvider) *Server

WithTracing registers the specified TracerProvider within the Server. Subsequent handlers can use s.trace to create more detailed traces than what it would be possible if we applied the same tracing middleware to the whole server.

func (*Server) WithWS

func (s *Server) WithWS() *Server

WithWS enables serving and handle websockets.

Jump to

Keyboard shortcuts

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