Files
ozon-mock/cmd/server/main.go
Rinat 50dc046369
Some checks failed
deploy / deploy (push) Failing after 2s
test / test (push) Failing after 1s
v2.0: massive test data (104 products, 41 postings, 20 returns, 20 payouts, 25 txs, 3 companies)
- Remove unused gin dependency from go.mod
- Remove credential logging from startup
- Remove dead parseOfferIDs function
- Add method check to GET /v1/product/list
- Complete all filter implementations (since, to, status, product_id, return_id, dir, analytics, page)
- CancelPosting now validates posting existence (404 for unknown)
- Implement MOCK_STOCKS_JSON file loading
- Add Phase 2 endpoints: v3/product/import, v1/product/info/description,
  v1/product/info/attributes, v2/category/tree, v3/category/attribute,
  v3/category/attribute/values
- Generate 104 products/stocks/prices across 3 companies:
  TechGiant (TG-0001..TG-0035), FashionLine (FL-0001..FL-0035), HomeStyle (HS-0001..HS-0034)
- 41 postings, 20 returns, 20 payouts, 25 transactions
- 31 tests (all PASS with race detector)
- Add Makefile
2026-07-17 14:38:53 +03:00

71 lines
2.4 KiB
Go

package main
import (
"log"
"net/http"
"github.com/rinat/ozon-mock/internal/config"
"github.com/rinat/ozon-mock/internal/handlers"
"github.com/rinat/ozon-mock/internal/middleware"
)
func main() {
cfg := config.Load()
mux := http.NewServeMux()
auth := func(h http.HandlerFunc) http.HandlerFunc {
return middleware.Auth(cfg.ClientID, cfg.APIKey, h)
}
// Products
mux.HandleFunc("/v1/product/import/prices", auth(handlers.ImportPrices))
mux.HandleFunc("/v1/product/list", auth(handlers.ProductList))
mux.HandleFunc("/v3/product/info/list", auth(handlers.ProductInfoList))
mux.HandleFunc("/v3/product/info/stocks", auth(handlers.ProductStocks))
mux.HandleFunc("/v4/product/info/prices", auth(handlers.ProductPrices))
// Product cards (Phase 2)
mux.HandleFunc("/v3/product/import", auth(handlers.ImportProducts))
mux.HandleFunc("/v1/product/info/description", auth(handlers.ProductDescriptions))
mux.HandleFunc("/v1/product/info/attributes", auth(handlers.ProductAttributes))
// Categories (Phase 2)
mux.HandleFunc("/v2/category/tree", auth(handlers.CategoryTree))
mux.HandleFunc("/v3/category/attribute", auth(handlers.CategoryAttributes))
mux.HandleFunc("/v3/category/attribute/values", auth(handlers.CategoryAttributeValues))
// Postings
mux.HandleFunc("/v2/posting/fbs/list", auth(handlers.PostingFBSList))
mux.HandleFunc("/v2/posting/fbs/get", auth(handlers.PostingFBSGet))
mux.HandleFunc("/v1/posting/fbs/cancel", auth(handlers.CancelPosting))
// Finance
mux.HandleFunc("/v1/finance/transaction/list", auth(handlers.FinanceTransactionList))
mux.HandleFunc("/v1/finance/payout/list", auth(handlers.FinancePayoutList))
// Returns
mux.HandleFunc("/v1/returns/list", auth(handlers.ReturnsList))
// Analytics
mux.HandleFunc("/v1/analytics/data", auth(handlers.AnalyticsData))
mux.HandleFunc("/v1/analytics/turnover/stocks", auth(handlers.TurnoverStocks))
// Health
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"status":"ok"}`))
})
// 404 handler
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(`{"code":404,"message":"not found"}`))
})
addr := ":" + cfg.Port
log.Printf("Starting ozon-mock on %s", addr)
log.Fatal(http.ListenAndServe(addr, mux))
}