first commit

This commit is contained in:
Beyhan Ogur
2026-05-11 15:08:50 +03:00
commit a408821410
47 changed files with 4670 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
# OpenAI Flow
**Özet:** OpenAI-compatible isteklerin gateway üzerinden direkt passthrough akışı.
**Kütüphaneler:** Fiber v3, Go `net/http`
**Bağlantılar:** [[OpenAIHandler]], [[ProxyEngine]], [[RequestLog]], [[Index]]
## Akış Diyagramı
```mermaid
sequenceDiagram
participant Client
participant Gateway
participant Proxy
participant Upstream
participant DB
Client->>Gateway: POST /v1/chat/completions
Note over Gateway: OpenAIHandler
Gateway->>Gateway: fiberToHTTPHeaders()
Gateway->>Gateway: API key auto-inject (gerekirse)
Gateway->>Gateway: copyResponseHeaders()
Gateway->>Proxy: Forward(method, targetURL, headers, body, timeout)
Proxy->>Upstream: POST <OPENAI_BACKEND>/v1/chat/completions
Upstream-->>Proxy: 200 OK + response body
Proxy-->>Gateway: ForwardResult{StatusCode, Body, Headers}
Gateway->>Gateway: copyResponseHeaders() (skip hop-by-hop)
Gateway->>DB: go db.Create(logEntry) — fire-and-forget
Gateway-->>Client: 200 OK + original response body
```
## Önemli Noktalar
- İstek body'si **olduğu gibi** iletilir (dönüşüm yok)
- Response header'ları kopyalanırken `Transfer-Encoding`, `Content-Length`, `Connection` atlanır
- Upstream hatasında client `502 Bad Gateway` alır
- DB loglama bir goroutine içinde çalışır, asla ana isteği bloke etmez