http

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FaviconHandler added in v0.13.0

func FaviconHandler() http.Handler

func LogTraceID added in v0.12.1

func LogTraceID(next http.Handler) http.Handler

func PrometheusMiddleware

func PrometheusMiddleware(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) Authenticate added in v0.13.3

func (c CatalogClient) Authenticate() (*model.User, error)

Authenticate authenticates the token against the /api/users/token/authenticate endpoint. The token will be taken from the authentication information in c.ctx, under the authKey key. Its value should be "token <TOKEN>".

func (CatalogClient) Doughs

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

func (CatalogClient) GetRecommendation added in v0.12.1

func (c CatalogClient) GetRecommendation(id int) (*model.Pizza, error)

func (CatalogClient) Ingredients

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

func (CatalogClient) RecordRecommendation

func (c CatalogClient) RecordRecommendation(p model.Pizza) (*model.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 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      model.Pizza `json:"pizza"`
	Calories   int         `json:"calories"`
	Vegetarian bool        `json:"vegetarian"`
}

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

type Restrictions added in v0.5.0

type Restrictions struct {
	MaxCaloriesPerSlice int      `json:"maxCaloriesPerSlice"`
	MustBeVegetarian    bool     `json:"mustBeVegetarian"`
	ExcludedIngredients []string `json:"excludedIngredients"`
	ExcludedTools       []string `json:"excludedTools"`
	MaxNumberOfToppings int      `json:"maxNumberOfToppings"`
	MinNumberOfToppings int      `json:"minNumberOfToppings"`
}

Restrictions are sent by the client to further specify how the target pizza should look like

func (Restrictions) WithDefaults added in v0.5.0

func (r Restrictions) WithDefaults() Restrictions

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(profiling bool, traceInstaller *TraceInstaller) *Server

func (*Server) AddCatalogHandler added in v0.13.2

func (s *Server) AddCatalogHandler(db *database.Catalog)

AddCatalogHandler enables routes related to the ingredients, doughs, tools, ratings and users. 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) AddConfigHandler added in v0.13.2

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

AddConfigHandler enables serving the config server.

func (*Server) AddCopyHandler added in v0.13.2

func (s *Server) AddCopyHandler(db *database.Copy)

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

func (*Server) AddFrontend added in v0.13.2

func (s *Server) AddFrontend()

AddFrontend enables serving the embedded Svelte frontend.

func (*Server) AddGateway added in v0.13.2

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

AddGateway 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) AddHTTPTesting added in v0.13.2

func (s *Server) AddHTTPTesting()

AddHTTPTesting enables routes for simple HTTP endpoint testing, like in httpbin.org. These are meant to replace https://github.com/grafana/httpbin (roughly).

func (*Server) AddLivenessProbes added in v0.13.2

func (s *Server) AddLivenessProbes()

func (*Server) AddPrometheusHandler added in v0.13.2

func (s *Server) AddPrometheusHandler()

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

func (*Server) AddRecommendations added in v0.13.2

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

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

func (*Server) AddTestK6IO added in v0.14.0

func (s *Server) AddTestK6IO()

AddTestK6IO enables routes for replacing the legacy test.k6.io service. It tries to follow https://github.com/grafana/test.k6.io as closely as possible, even though the original service was implemented in PHP. For this reason, the paths defined here will sometimes end in '.php'.

func (*Server) AddWebSocket added in v0.13.2

func (s *Server) AddWebSocket()

AddWebSocket enables serving and handle websockets.

func (*Server) AuthMiddleware added in v0.13.3

func (s *Server) AuthMiddleware(db *database.Catalog) func(http.Handler) http.Handler

func (*Server) AuthViaCatalogClientMiddleware added in v0.13.3

func (s *Server) AuthViaCatalogClientMiddleware(catalogClient CatalogClient) func(http.Handler) http.Handler

func (*Server) ServeHTTP

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

type TraceInstaller added in v0.5.0

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

TraceInstaller installs tracing middleware into a chi router. An uninitialized TraceInstaller behaves like a noop, where calls to Install have no effect.

func NewTraceInstaller added in v0.5.0

func NewTraceInstaller(ctx context.Context, endpointUrl string) (*TraceInstaller, error)

NewTraceInstaller creates a new initialized TraceInstaller that will set up traces and push them.

func (*TraceInstaller) Insecure added in v0.5.0

func (t *TraceInstaller) Insecure()

Insecure instructs the TraceInstaller to trust incoming trace IDs.

func (*TraceInstaller) Install added in v0.5.0

func (t *TraceInstaller) Install(r chi.Router, serviceName string, extraOpts ...otelhttp.Option)

Install adds tracing middleware to the supplied chi.Router. extraOpts take precedence over the default opts.

Jump to

Keyboard shortcuts

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