Files
opantoantro/docs/wiki/Main.md
T
Beyhan Ogur a408821410 first commit
2026-05-11 15:08:50 +03:00

37 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Main
**Özet:** Uygulamanın giriş noktası (`main.go:38`). Fiber v3 web framework'ünü başlatır, `DB_MODE`'a göre PostgreSQL veya SQLite bağlantısını kurar, AutoMigrate çalıştırır ve tüm route'ları tanımlar.
**Kütüphaneler:** Fiber v3, GORM, PostgreSQL, SQLite, godotenv
**Bağlantılar:** [[Index]], [[Config]], [[RequestLog]], [[OpenAIHandler]], [[AnthropicHandler]], [[HealthHandler]], [[SwaggerUI]], [[DockerSetup]]
## Başlangıç Adımları
1. `.env` dosyası yüklenir (`godotenv.Load()`)
2. [[Config]] okunur (`config.Load()`)
3. `DB_MODE` kontrol edilir — PostgreSQL DSN veya SQLite bağlantısı + AutoMigrate (`RequestLog`)
4. Fiber v3 app oluşturulur (`fiber.Config{AppName: "LLM Gateway v1.0", ServerHeader: "optoant-gateway"}`)
5. Route'lar tanımlanır:
- `GET /health` → [[HealthHandler]]
- `GET /swagger/swagger.json` → statik dosya serve
- `GET /swagger``/swagger/` redirect
- `GET /swagger/*` → Swagger UI HTML (CDN)
- `ALL /v1/*` → [[OpenAIHandler]] (direct passthrough)
- `ALL /anthropic`, `/anthropic/*` → [[AnthropicHandler]] (Bifrost dönüşümü)
6. `app.Listen(addr)` ile server başlatılır
## Önemli Detaylar
- DB bağlantısı başarısız olursa uygulama **devam eder** (DB'siz çalışabilir)
- Tüm backend istekleri `.env`'deki `OPENAI_BACKEND` adresine gider
- OpenAI endpoint'i direkt passthrough yaparken, Anthropic endpoint'i format dönüşümü yapar
- Swagger UI **CDN'den** yüklenir (offline çalışmaz)
- API key auto-injection: `OPENAI_KEY` env'i tanımlıysa, client Authorization göndermezse otomatik eklenir
## Geliştirme
- **Air hot-reload:** `.air.toml` ile canlı yeniden derleme (`air`)
- **Production build:** `build.sh` ile `CGO_ENABLED=0` optimize binary
- **Docker:** `docker/Dockerfile` multi-stage + `docker-compose.yml`