Documentation
¶
Index ¶
- func FaviconHandler() http.Handler
- func HTTPMetricsMiddleware(next http.Handler) http.Handler
- func LogTraceID(next http.Handler) http.Handler
- func LogUser(next http.Handler) http.Handler
- func OTelRouteLabeler(next http.Handler) http.Handler
- func SvelteKitHandler() http.Handler
- func ViteProxyHandler() http.Handler
- type CatalogClient
- func (c CatalogClient) Authenticate() (*model.User, error)
- func (c CatalogClient) Doughs() ([]model.Dough, error)
- func (c CatalogClient) GetRecommendation(id int) (*model.Pizza, error)
- func (c CatalogClient) Ingredients(ingredientType string) ([]model.Ingredient, error)
- func (c CatalogClient) RecordRecommendation(p model.Pizza) (*model.Pizza, error)
- func (c CatalogClient) Tools() ([]string, error)
- func (c CatalogClient) WithClient(client *http.Client) CatalogClient
- func (c CatalogClient) WithRequestContext(ctx context.Context) CatalogClient
- type CopyClient
- type OTelInstaller
- type PizzaRecommendation
- type Restrictions
- type Server
- func (s *Server) AddCatalogHandler(db *database.Catalog)
- func (s *Server) AddConfigHandler(config map[string]string)
- func (s *Server) AddCopyHandler(db *database.Copy)
- func (s *Server) AddFrontend(devMode bool)
- func (s *Server) AddGateway(catalogUrl, copyUrl, wsUrl, recommendationsUrl, configUrl string)
- func (s *Server) AddHTTPTesting()
- func (s *Server) AddLivenessProbes()
- func (s *Server) AddPrometheusHandler()
- func (s *Server) AddRecommendations(catalogClient CatalogClient, copyClient CopyClient)
- func (s *Server) AddTestK6IO()
- func (s *Server) AddWebSocket()
- func (s *Server) AuthMiddleware(db *database.Catalog) func(http.Handler) http.Handler
- func (s *Server) AuthViaCatalogClientMiddleware(catalogClient CatalogClient) func(http.Handler) http.Handler
- func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FaviconHandler ¶ added in v0.13.0
func HTTPMetricsMiddleware ¶ added in v0.15.21
HTTPMetricsMiddleware records Prometheus metrics for HTTP requests. It captures request count, duration (histogram), and duration (gauge) with labels for method, path (route pattern), and status code.
func OTelRouteLabeler ¶ added in v0.15.21
OTelRouteLabeler is a middleware that adds the chi route pattern to OTel metrics. This must be used AFTER otelhttp.NewHandler and will add an "http.route" label to the http_server_request_duration_seconds metric.
Note: otelhttp.WithMetricAttributesFn cannot be used for this because the chi route pattern is only resolved after routing, but WithMetricAttributesFn runs before the handler. The Labeler is the recommended approach for dynamic attributes.
func ViteProxyHandler ¶ added in v0.15.17
ViteProxyHandler returns an http.Handler that proxies requests to the Vite dev server.
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) 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 (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 OTelInstaller ¶ added in v0.15.7
type OTelInstaller struct {
// contains filtered or unexported fields
}
OTelInstaller installs tracing middleware into a chi router. An uninitialized OTelInstaller behaves like a noop, where calls to Install have no effect.
func NewOTelInstaller ¶ added in v0.15.7
func NewOTelInstaller(ctx context.Context, endpointUrl string) (*OTelInstaller, error)
NewOTelInstaller creates a new OTelInstaller. Call Install to set up traces and metrics.
func (*OTelInstaller) Insecure ¶ added in v0.15.7
func (t *OTelInstaller) Insecure()
Insecure instructs the OTelInstaller to trust incoming trace IDs.
func (*OTelInstaller) Install ¶ added in v0.15.7
func (t *OTelInstaller) Install(r chi.Router, serviceComponent string, extraOpts ...otelhttp.Option) error
Install OTel, - sets global OTel tracer and meter providers when called first time - enable runtime metrics only once - enable HTTP tracing and metrics on the supplied chi.Router extraOpts take precedence over the default opts
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"`
CustomName string `json:"customName"`
}
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 *OTelInstaller) *Server
func (*Server) AddCatalogHandler ¶ added in v0.13.2
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
AddConfigHandler enables serving the config server.
func (*Server) AddCopyHandler ¶ added in v0.13.2
AddCopyHandler enables copy (i.e. prose) related endpoints.
func (*Server) AddFrontend ¶ added in v0.13.2
AddFrontend enables serving the embedded Svelte frontend.
func (*Server) AddGateway ¶ added in v0.13.2
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.