first commit
This commit is contained in:
328
docs/SETUP.md
Normal file
328
docs/SETUP.md
Normal file
@@ -0,0 +1,328 @@
|
||||
# 🚀 GAuth-Central Kurulum Rehberi
|
||||
|
||||
## Hızlı Başlangıç
|
||||
|
||||
### Option 1: Standalone Mode (Mevcut Sunucular ile)
|
||||
|
||||
Eğer zaten çalışan PostgreSQL ve Redis sunucularınız varsa:
|
||||
|
||||
```bash
|
||||
# 1. .env dosyasını kontrol edin ve sunucu bilgilerini girin
|
||||
# DB_URL="host=YOUR_HOST user=YOUR_USER password=YOUR_PASS dbname=YOUR_DB..."
|
||||
# REDIS_URL=redis://user:pass@YOUR_HOST:6379/0
|
||||
|
||||
# 2. Uygulamayı başlatın
|
||||
./start.sh
|
||||
```
|
||||
|
||||
Script şunları yapacaktır:
|
||||
- ✅ .env dosyasını kontrol eder
|
||||
- ✅ PostgreSQL bağlantısını test eder
|
||||
- ✅ Redis bağlantısını test eder
|
||||
- ✅ Uygulamayı derler ve başlatır
|
||||
|
||||
### Option 2: Docker ile (Yeni Kurulum)
|
||||
|
||||
```bash
|
||||
# 1. Start-with-docker scriptini çalıştırın
|
||||
./start-with-docker.sh
|
||||
|
||||
# 2. Logları izleyin
|
||||
docker-compose logs -f app
|
||||
```
|
||||
|
||||
### Option 2: Docker ile (Yeni Kurulum)
|
||||
|
||||
```bash
|
||||
# 1. Start-with-docker scriptini çalıştırın
|
||||
./start-with-docker.sh
|
||||
|
||||
# 2. Logları izleyin
|
||||
docker-compose logs -f app
|
||||
```
|
||||
|
||||
### Option 3: Manuel Kurulum (Sadece Uygulama)
|
||||
|
||||
**Not:** Bu option mevcut PostgreSQL ve Redis sunucularınızla çalışmak için kullanılır.
|
||||
|
||||
#### 1. Bağımlılıkları Yükleyin
|
||||
|
||||
```bash
|
||||
go mod download
|
||||
```
|
||||
|
||||
#### 2. .env Dosyasını Yapılandırın
|
||||
|
||||
```bash
|
||||
# .env dosyasını düzenleyin
|
||||
nano .env
|
||||
```
|
||||
|
||||
Gerekli ayarlar:
|
||||
```env
|
||||
PORT=8080
|
||||
|
||||
# Mevcut PostgreSQL sunucunuz
|
||||
DB_URL="host=10.80.80.70 user=cloud password=xxx dbname=go_gauth port=5432 sslmode=disable TimeZone=Europe/Istanbul"
|
||||
|
||||
# Mevcut Redis sunucunuz
|
||||
REDIS_URL=redis://default:xxx@10.80.80.70:6379/0
|
||||
|
||||
# JWT Secret
|
||||
JWT_SECRET=your_super_secret_key
|
||||
|
||||
# OAuth credentials (opsiyonel)
|
||||
GOOGLE_CLIENT_ID=...
|
||||
GOOGLE_CLIENT_SECRET=...
|
||||
GITHUB_CLIENT_ID=...
|
||||
GITHUB_CLIENT_SECRET=...
|
||||
CLIENT_CALLBACK_URL=http://localhost:8080/v1/auth
|
||||
```
|
||||
|
||||
#### 3. Uygulamayı Çalıştırın
|
||||
|
||||
```bash
|
||||
# Quick start script ile
|
||||
./start.sh
|
||||
|
||||
# veya manuel
|
||||
go build -o main .
|
||||
./main
|
||||
|
||||
# veya doğrudan
|
||||
go run main.go
|
||||
```
|
||||
|
||||
### Option 4: Docker ile Sadece Veritabanları
|
||||
|
||||
### Option 4: Docker ile Sadece Veritabanları
|
||||
|
||||
Eğer uygulamayı local'de çalıştırıp sadece veritabanlarını Docker'da tutmak isterseniz:
|
||||
|
||||
#### 1. PostgreSQL'i Başlatın
|
||||
|
||||
```bash
|
||||
docker run -d \
|
||||
--name gauth_postgres \
|
||||
-e POSTGRES_USER=postgres \
|
||||
-e POSTGRES_PASSWORD=yourpassword \
|
||||
-e POSTGRES_DB=gauth \
|
||||
-p 5432:5432 \
|
||||
postgres:17-alpine
|
||||
```
|
||||
|
||||
#### 2. Redis'i Başlatın
|
||||
|
||||
```bash
|
||||
# Docker ile
|
||||
docker run -d \
|
||||
--name gauth_redis \
|
||||
-p 6379:6379 \
|
||||
redis:7-alpine
|
||||
```
|
||||
|
||||
#### 4. .env Dosyasını Yapılandırın
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
# .env dosyasını düzenleyin
|
||||
```
|
||||
|
||||
Örnek .env:
|
||||
```env
|
||||
PORT=8080
|
||||
DB_URL="host=localhost user=postgres password=yourpassword dbname=gauth port=5432 sslmode=disable TimeZone=Europe/Istanbul"
|
||||
REDIS_URL=redis://localhost:6379/0
|
||||
JWT_SECRET=your_super_secret_key
|
||||
```
|
||||
|
||||
#### 5. Uygulamayı Çalıştırın
|
||||
|
||||
```bash
|
||||
# Geliştirme modu
|
||||
go run main.go
|
||||
|
||||
# Veya derleyip çalıştırın
|
||||
go build -o main .
|
||||
./main
|
||||
```
|
||||
|
||||
## 🔧 Yapılandırma Detayları
|
||||
|
||||
### PostgreSQL Bağlantısı
|
||||
|
||||
Uygulamanız PostgreSQL veritabanına bağlanacak ve otomatik olarak:
|
||||
- Tabloları oluşturacak (migration)
|
||||
- Seed data ekleyecek (roles, permissions)
|
||||
- Email doğrulama sütununu güncelleyecek
|
||||
|
||||
### Redis Cache
|
||||
|
||||
Redis aşağıdaki amaçlarla kullanılır:
|
||||
|
||||
1. **Session Yönetimi**: Token-based session storage
|
||||
2. **Rate Limiting**: API çağrılarını sınırlandırma
|
||||
3. **Cache**: Kullanıcı verileri ve sık erişilen datalar
|
||||
4. **Token Blacklist**: Logout işlemlerinde token iptal
|
||||
5. **Email Verification**: Email doğrulama token'ları
|
||||
6. **Password Reset**: Şifre sıfırlama token'ları
|
||||
|
||||
### CORS Yapılandırması
|
||||
|
||||
Varsayılan olarak `http://localhost:3000` origin'ine izin verilir. Değiştirmek için `main.go` dosyasını düzenleyin:
|
||||
|
||||
```go
|
||||
AllowOrigins: []string{"http://localhost:3000", "https://yourdomain.com"},
|
||||
```
|
||||
|
||||
## 🧪 Test Etme
|
||||
|
||||
### 1. Sağlık Kontrolü
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/
|
||||
```
|
||||
|
||||
### 2. Swagger UI
|
||||
|
||||
Tarayıcınızda: `http://localhost:8080/docs/index.html`
|
||||
|
||||
### 3. Kullanıcı Kaydı
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/v1/auth/register \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"email": "test@example.com",
|
||||
"password": "SecurePass123!",
|
||||
"user_name": "testuser"
|
||||
}'
|
||||
```
|
||||
|
||||
### 4. Giriş
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/v1/auth/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"email": "test@example.com",
|
||||
"password": "SecurePass123!"
|
||||
}'
|
||||
```
|
||||
|
||||
### 5. Redis Bağlantı Kontrolü
|
||||
|
||||
```bash
|
||||
# Redis CLI ile
|
||||
docker exec -it gauth_redis redis-cli
|
||||
|
||||
# Redis içinde
|
||||
> PING
|
||||
PONG
|
||||
|
||||
> KEYS *
|
||||
(Redis'teki tüm key'leri gösterir)
|
||||
|
||||
> GET user:UUID_HERE
|
||||
(Kullanıcı cache verisi)
|
||||
```
|
||||
|
||||
### 6. PostgreSQL Bağlantı Kontrolü
|
||||
|
||||
```bash
|
||||
# PostgreSQL CLI ile
|
||||
docker exec -it gauth_postgres psql -U postgres -d gauth
|
||||
|
||||
# PostgreSQL içinde
|
||||
\dt -- Tabloları listele
|
||||
\d users -- Users tablosu yapısını göster
|
||||
SELECT * FROM roles; -- Rolleri listele
|
||||
```
|
||||
|
||||
## 📊 Rate Limiting Yapılandırması
|
||||
|
||||
Varsayılan limitler:
|
||||
|
||||
- **Login**: 5 deneme / dakika
|
||||
- **Register**: 3 deneme / 5 dakika
|
||||
- **Genel API**: 100 istek / dakika
|
||||
|
||||
Değiştirmek için `api/middlewares/rate_limit_middleware.go` dosyasını düzenleyin.
|
||||
|
||||
## 🔐 OAuth Yapılandırması
|
||||
|
||||
### Google OAuth
|
||||
|
||||
1. [Google Cloud Console](https://console.cloud.google.com/) → API & Services → Credentials
|
||||
2. OAuth 2.0 Client ID oluşturun
|
||||
3. Authorized redirect URIs: `http://localhost:8080/v1/auth/google/callback`
|
||||
4. Client ID ve Secret'ı `.env` dosyasına ekleyin
|
||||
|
||||
### GitHub OAuth
|
||||
|
||||
1. [GitHub Developer Settings](https://github.com/settings/developers) → OAuth Apps → New
|
||||
2. Authorization callback URL: `http://localhost:8080/v1/auth/github/callback`
|
||||
3. Client ID ve Secret'ı `.env` dosyasına ekleyin
|
||||
|
||||
## 🐛 Sorun Giderme
|
||||
|
||||
### Redis bağlanamıyor
|
||||
|
||||
```bash
|
||||
# Redis durumunu kontrol et
|
||||
docker ps | grep redis
|
||||
|
||||
# Redis loglarını kontrol et
|
||||
docker logs gauth_redis
|
||||
|
||||
# Redis'i yeniden başlat
|
||||
docker restart gauth_redis
|
||||
```
|
||||
|
||||
### PostgreSQL bağlanamıyor
|
||||
|
||||
```bash
|
||||
# PostgreSQL durumunu kontrol et
|
||||
docker ps | grep postgres
|
||||
|
||||
# PostgreSQL loglarını kontrol et
|
||||
docker logs gauth_postgres
|
||||
|
||||
# Bağlantıyı test et
|
||||
docker exec -it gauth_postgres pg_isready -U postgres
|
||||
```
|
||||
|
||||
### CORS hatası alıyorum
|
||||
|
||||
`main.go` dosyasında `AllowOrigins` değerini kontrol edin ve frontend URL'inizi ekleyin.
|
||||
|
||||
### Rate limit çok düşük
|
||||
|
||||
`api/middlewares/rate_limit_middleware.go` dosyasında limit değerlerini artırın.
|
||||
|
||||
## 📝 Notlar
|
||||
|
||||
- Üretim ortamında `JWT_SECRET` değerini güçlü bir değerle değiştirin
|
||||
- Redis şifre koruması için production'da Redis AUTH kullanın
|
||||
- PostgreSQL için SSL bağlantısı kullanın (sslmode=require)
|
||||
- Log seviyelerini production'da ayarlayın
|
||||
- CORS origin'lerini production domain'lerinizle güncelleyin
|
||||
|
||||
## 🔄 Güncellemeler
|
||||
|
||||
Swagger dokümantasyonunu güncellemek için:
|
||||
|
||||
```bash
|
||||
swag init -g main.go
|
||||
```
|
||||
|
||||
Migration eklemek için:
|
||||
|
||||
`internal/database/db.go` dosyasındaki `Migrate()` fonksiyonunu güncelleyin.
|
||||
|
||||
## 📚 Daha Fazla Bilgi
|
||||
|
||||
- [Gin Web Framework](https://gin-gonic.com/)
|
||||
- [GORM ORM](https://gorm.io/)
|
||||
- [Redis Go Client](https://redis.uptrace.dev/)
|
||||
- [JWT Go](https://github.com/golang-jwt/jwt)
|
||||
Reference in New Issue
Block a user