Documentation
¶
Overview ¶
@title Checkout Service API @version 1.0 @description API for managing inventory and orders @host localhost:8000 @BasePath /
Index ¶
- Variables
- func Status() httprouter.Handle
- type API
- type HTTPServer
- func (h *HTTPServer) AddItems() httprouter.Handle
- func (h *HTTPServer) Addr() string
- func (h *HTTPServer) Health() httprouter.Handle
- func (h *HTTPServer) ItemPrice() httprouter.Handle
- func (h *HTTPServer) ItemsPrice() httprouter.Handle
- func (h *HTTPServer) Orders() httprouter.Handle
- func (h *HTTPServer) PurchaseItems() httprouter.Handle
- func (h *HTTPServer) Start()
- func (h *HTTPServer) Stop() error
- type JSONError
Constants ¶
This section is empty.
Variables ¶
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" )
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 HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer handles requests and access to the connected Database.
func NewHTTPServer ¶
func NewHTTPServer(port int, l logrus.FieldLogger, db database.Database, authPasswd string) *HTTPServer
NewHTTPServer returns a HTTPServer with httprouter Router handling requests.
func (*HTTPServer) AddItems ¶
func (h *HTTPServer) 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 (*HTTPServer) Addr ¶
func (h *HTTPServer) Addr() string
func (*HTTPServer) Health ¶
func (h *HTTPServer) 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 (*HTTPServer) ItemPrice ¶
func (h *HTTPServer) 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 (*HTTPServer) ItemsPrice ¶
func (h *HTTPServer) 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 (*HTTPServer) Orders ¶
func (h *HTTPServer) 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 (*HTTPServer) PurchaseItems ¶
func (h *HTTPServer) 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 (*HTTPServer) Start ¶
func (h *HTTPServer) Start()
Start spawns the server which will listen on the TCP address srv.Addr for incoming requests.
func (*HTTPServer) Stop ¶
func (h *HTTPServer) Stop() error
Stop gracefully shuts down the HTTP server.