server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

@title Checkout Service API @version 1.0 @description API for managing inventory and orders @host localhost:8000 @BasePath /

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusEndPnt = "/status"
	HealthEndPnt = "/health"

	ItemsEndPnt        = "/v0/inventory/items"
	ItemPriceEndPnt    = "/v0/inventory/item/price"
	ItemsPriceEndPnt   = "/v0/inventory/items/price"
	ItemPurchaseEndPnt = "/v0/inventory/items/purchase"
	KeyParam           = "/:key"

	OrdersEndPnt = "/v0/orders"
)
View Source
var (
	// RequestDuration stores HTTP request execution duration data to be served by the Prometheus metrics server.
	RequestDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "http_request_duration_seconds",
			Help:    "Duration of HTTP requests in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"method", "path", "status_code"},
	)
	// RequestCount is an incremental counter measuring the total request count for each route and response status code.
	RequestCount = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "http_request_count_total",
			Help: "Total number of HTTP requests",
		},
		[]string{"method", "path", "status_code"},
	)
)

Functions

func Status

func Status() httprouter.Handle

Status godoc @Summary Get service status @Description Returns the status of the service @Tags status @Produce json @Success 200 {object} StatusResponse @Failure 500 {object} JSONError @Router /status [get]

Types

type API

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

API is a collection of endpoints.

type JSONError

type JSONError struct {
	Error string `json:"error,omitempty"`
}

type Server added in v0.1.0

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

Server handles requests and access to the connected Database.

func NewServer added in v0.1.0

func NewServer(port int, l logrus.FieldLogger, db database.Database, authPasswd string) *Server

NewHTTPServer returns a HTTPServer with httprouter Router handling requests.

func (*Server) AddItems added in v0.1.0

func (h *Server) AddItems() httprouter.Handle

AddItems godoc @Summary Add new or updated items to the inventory table @Description Add new or updated items @Tags inventory @Accept json @Produce json @Param skus body AddItemsRequest true "List of Items" @Success 200 @Failure 400 {object} JSONError @Failure 404 {object} JSONError @Failure 503 {object} JSONError @Router /v0/inventory/items [post]

func (*Server) Addr added in v0.1.0

func (h *Server) Addr() string

func (*Server) Health added in v0.1.0

func (h *Server) Health() httprouter.Handle

Health godoc @Summary Get service health @Description Checks the health of the service and its dependencies. @Tags health @Produce json @Success 200 {object} HealthResponse @Failure 503 {object} HealthResponse @Failure 500 {object} JSONError @Router /health [get]

func (*Server) ItemPrice added in v0.1.0

func (h *Server) ItemPrice() httprouter.Handle

ItemPrice godoc @Summary Get price for a single item @Description Get price information for a single item by SKU or name @Tags inventory @Produce json @Param key path string true "Item SKU or Name" @Success 200 {object} PriceResponse @Failure 400 {object} JSONError @Failure 404 {object} JSONError @Router /v0/inventory/item/price/{key} [get]

func (*Server) ItemsPrice added in v0.1.0

func (h *Server) ItemsPrice() httprouter.Handle

ItemsPrice godoc @Summary Get prices for multiple items @Description Get total price for a batch of items by SKUs @Tags inventory @Accept json @Produce json @Param skus body PriceItemsRequest true "List of SKUs" @Success 200 {object} PriceResponse @Failure 400 {object} JSONError @Failure 404 {object} JSONError @Failure 503 {object} JSONError @Router /v0/inventory/items/price [post]

func (*Server) Orders added in v0.1.0

func (h *Server) Orders() httprouter.Handle

Orders godoc @Summary Get list of purchase orders @Description List all purchase orders @Tags inventory @Produce json @Success 200 {object} Orders @Failure 400 {object} JSONError @Failure 404 {object} JSONError @Failure 503 {object} JSONError @Router /v0/orders [get]

func (*Server) PurchaseItems added in v0.1.0

func (h *Server) PurchaseItems() httprouter.Handle

PurchaseItems godoc @Summary Execute a purchase for the supplied item list. @Description Create a purchase order for the supplied item list. @Tags inventory @Accept json @Produce json @Param skus body PurchaseItemsRequest true "List of SKUs" @Success 200 {object} PurchaseItemsResponse @Failure 400 {object} JSONError @Failure 404 {object} JSONError @Failure 503 {object} JSONError @Router /v0/inventory/items/purchase [post]

func (*Server) Start added in v0.1.0

func (h *Server) Start()

Start spawns the server which will listen on the TCP address srv.Addr for incoming requests.

func (*Server) Stop added in v0.1.0

func (h *Server) Stop() error

Stop gracefully shuts down the HTTP server.

Jump to

Keyboard shortcuts

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