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)) }