Initial commit: ozon-mock Go server

- Mock Ozon Seller API endpoints
- Products, Postings, Finance, Returns, Analytics
- JSON fixtures for testing
- Docker support
- Gitea Actions CI/CD
This commit is contained in:
Rinat
2026-07-15 16:19:24 +03:00
commit 842f87f576
13 changed files with 1285 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package middleware
import (
"encoding/json"
"net/http"
)
func Auth(expectedClientID, expectedAPIKey string, next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
clientID := r.Header.Get("Client-Id")
apiKey := r.Header.Get("Api-Key")
if clientID == "" || apiKey == "" {
writeError(w, 401, "missing credentials: Client-Id and Api-Key headers are required")
return
}
if expectedClientID != "" && clientID != expectedClientID {
writeError(w, 403, "invalid client id")
return
}
if expectedAPIKey != "" && apiKey != expectedAPIKey {
writeError(w, 403, "invalid api key")
return
}
next(w, r)
}
}
func writeError(w http.ResponseWriter, code int, msg string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
json.NewEncoder(w).Encode(map[string]any{
"code": code,
"message": msg,
})
}