Bu proje, Go programlama dili kullanılarak geliştirilmiş RESTful bir ürün yönetim API'sidir. API, Fiber web framework'ü, GORM ORM kütüphanesi ve SQLite veritabanı kullanılarak oluşturulmuştur.
- Ürün CRUD (Create, Read, Update, Delete) işlemleri
- Swagger UI ile API dokümantasyonu
- DTO (Data Transfer Object) modelleri ile veri validasyonu
- GORM ile veritabanı işlemleri
- CGO gerektirmeyen saf Go SQLite sürücüsü
- Fiber web framework ile hızlı ve verimli HTTP işleme
- Soft delete özelliği
- Otomatik zaman damgaları (created_at, updated_at)
- Go 1.22 veya üstü
-
Projeyi klonlayın:
git clone https://github.com/kullanici/product-api.git cd product-api -
Bağımlılıkları yükleyin:
go mod tidy
-
Projeyi çalıştırın:
go run main.go
-
API sunucusu
http://localhost:8080adresinde çalışmaya başlayacaktır.
API dokümantasyonuna http://localhost:8080/swagger/index.html adresinden erişebilirsiniz.
| Method | Endpoint | Açıklama |
|---|---|---|
| POST | /api/v1/products | Yeni bir ürün oluştur |
| GET | /api/v1/products | Tüm ürünleri listele |
| GET | /api/v1/products/:id | Belirli bir ürünü getir |
| PUT | /api/v1/products/:id | Var olan bir ürünü güncelle |
| DELETE | /api/v1/products/:id | Bir ürünü sil |
product-api/
├── database/ # Veritabanı yapılandırması ve bağlantısı
├── docs/ # Swagger tarafından oluşturulan API dokümantasyonu
├── models/ # Veri modelleri ve DTO'lar
├── repository/ # Veritabanı işlemleri (CRUD)
├── routes/ # API route tanımları ve handler'lar
├── data/ # SQLite veritabanı dosyası (çalışma zamanında oluşturulur)
├── main.go # Ana uygulama dosyası
└── README.md # Bu dosya
type Product struct {
ID uint `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"not null"`
Description string `json:"description"`
Price float64 `json:"price" gorm:"not null"`
Quantity int `json:"quantity" gorm:"default:0"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
SKU string `json:"sku"`
Barcode string `json:"barcode"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}type ProductCreateDTO struct {
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
Quantity int `json:"quantity"`
SKU string `json:"sku"`
Barcode string `json:"barcode"`
}
type ProductUpdateDTO struct {
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
Quantity int `json:"quantity"`
SKU string `json:"sku"`
Barcode string `json:"barcode"`
}{
"name": "Örnek Ürün",
"description": "Bu bir örnek ürün açıklamasıdır",
"price": 99.99,
"quantity": 10,
"sku": "ORN-12345",
"barcode": "1234567890123"
}{
"name": "Güncellenmiş Ürün",
"description": "Bu ürün açıklaması güncellenmiştir",
"price": 149.99,
"quantity": 5,
"sku": "ORN-54321",
"barcode": "3210987654321"
}- Go - Ana programlama dili
- Fiber - Hızlı, Express benzeri web framework
- GORM - Go için ORM kütüphanesi
- SQLite - Gömülü SQL veritabanı
- Swagger - API dokümantasyonu
- github.com/glebarez/sqlite - CGO gerektirmeyen saf Go SQLite sürücüsü
API dokümantasyonunu güncellemek için:
swag init- Kullanıcı kimlik doğrulama ve yetkilendirme
- Ürün kategorileri
- Gelişmiş arama ve filtreleme
- Resim yükleme desteği
- Sayfalama
- Loglama
- Birim ve entegrasyon testleri
Bu proje MIT Lisansı altında lisanslanmıştır.