Fiber, Go için en hızlı HTTP motoru olan Fasthttp üzerine inşa edilmiş, Express'ten ilham alan bir web frameworküdür. Sıfır bellek ataması ve performans göz önünde bulundurularak hızlı geliştirme için işleri kolaylaştırmak üzere tasarlanmıştır.
## ⚡️ Hızlı Başlangıç
```go
package main
import "github.com/gofiber/fiber/v2"
func main() {
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World 👋!")
})
app.Listen(":3000")
}
```
## 🤖 Performans Ölçümleri
Bu testler [TechEmpower](https://www.techempower.com/benchmarks/#section=data-r19&hw=ph&test=plaintext) ve [Go Web](https://github.com/smallnest/go-web-framework-benchmark) tarafından gerçekleştirildi. Bütün sonuçları görmek için lütfen [Wiki](https://docs.gofiber.io/extra/benchmarks) sayfasını ziyaret ediniz.
## ⚙️ Kurulum
Go'nun `1.14` sürümü ([indir](https://golang.org/dl/)) ya da daha yüksek bir sürüm gerekli.
Bir klasör oluşturup klasörün içinde `go mod init github.com/your/repo` yazarak projenize başlayın ([daha fazla öğren](https://blog.golang.org/using-go-modules)). Ardından Fiber'ı kurmak için [`go get`](https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) komutunu çalıştırın:
```bash
go get -u github.com/gofiber/fiber/v2
```
## 🎯 Özellikler
- Güçlü [rotalar](https://docs.gofiber.io/routing)
- [Statik dosya](https://docs.gofiber.io/api/app#static) sunumu
- Olağanüstü [performans](https://docs.gofiber.io/extra/benchmarks)
- [Düşük bellek](https://docs.gofiber.io/extra/benchmarks) tüketimi
- [API uç noktaları](https://docs.gofiber.io/api/ctx)
- Ara katman & [Sonraki](https://docs.gofiber.io/api/ctx#next) desteği
- [Hızlı](https://dev.to/koddr/welcome-to-fiber-an-express-js-styled-fastest-web-framework-written-with-on-golang-497) sunucu taraflı programlama
- [Template engines](https://github.com/gofiber/template)
- [WebSocket support](https://github.com/gofiber/websocket)
- [Rate Limiter](https://docs.gofiber.io/api/middleware/limiter)
- [15 dilde](https://docs.gofiber.io/) mevcut
- Ve daha fazlası, [Fiber'ı keşfet](https://docs.gofiber.io/)
## 💡 Felsefe
[Node.js](https://nodejs.org/en/about/)'ten [Go](https://golang.org/doc/)'ya geçen yeni gopherlar kendi web uygulamalarını ve mikroservislerini yazmaya başlamadan önce dili öğrenmek ile uğraşıyorlar. Fiber, bir **framework** olarak, **minimalizm** ve **UNIX yolu**nu izleme fikri ile oluşturuldu. Böylece yeni gopherlar sıcak ve güvenilir bir hoşgeldin ile Go dünyasına giriş yapabilirler.
Fiber internet üzerinde en popüler olan Express web frameworkünden **esinlenmiştir**. Biz Express'in **kolaylığını** ve Go'nun **ham performansını** birleştirdik. Daha önce Node.js üzerinde (Express veya benzerini kullanarak) bir web uygulaması geliştirdiyseniz, pek çok metod ve prensip size **çok tanıdık** gelecektir.
## Sınırlamalar
- Fiber unsafe kullanımı sebebiyle her zaman Go'nun son sürümüyle uyumlu olmayabilir. Fiber 2.18.0, Go 1.14 ile 1.17 sürümleriyle test edildi.
- Fiber net/http arabirimiyle uyumlu değildir. Yani gqlgen veya go-swagger gibi net/http ekosisteminin parçası olan projeleri kullanamazsınız.
## 👀 Örnekler
Aşağıda yaygın örneklerden bazıları listelenmiştir. Daha fazla kod örneği görmek için lütfen [Github reposunu](https://github.com/gofiber/recipes) veya [API dokümantasyonunu](https://docs.gofiber.io) ziyaret ediniz.
#### 📖 [**Basit Routelama**](https://docs.gofiber.io/#basic-routing)
```go
func main() {
app := fiber.New()
// GET /api/kayit
app.Get("/api/*", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("✋ %s", c.Params("*"))
return c.SendString(msg) // => ✋ kayit
})
// GET /flights/IST-ESB
app.Get("/flights/:kalkis-:inis", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("💸 Kalkış: %s, İniş: %s", c.Params("kalkis"), c.Params("inis"))
return c.SendString(msg) // => 💸 Kalkış: IST, İniş: ESB
})
// GET /sozluk.txt
app.Get("/:file.:ext", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("📃 %s.%s", c.Params("file"), c.Params("ext"))
return c.SendString(msg) // => 📃 sozluk.txt
})
// GET /muhittin/75
app.Get("/:isim/:yas/:cinsiyet?", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("👴 %s %s yaşında", c.Params("isim"), c.Params("yas"))
return c.SendString(msg) // => 👴 muhittin 75 yaşında
})
// GET /muhittin
app.Get("/:isim", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("Merhaba, %s 👋!", c.Params("isim"))
return c.SendString(msg) // => Merhaba Muhittin 👋!
})
log.Fatal(app.Listen(":3000"))
}
```
#### 📖 [**Statik Dosya Sunumu**](https://docs.gofiber.io/api/app#static)
```go
func main() {
app := fiber.New()
app.Static("/", "./public")
// => http://localhost:3000/js/script.js
// => http://localhost:3000/css/style.css
app.Static("/prefix", "./public")
// => http://localhost:3000/prefix/js/script.js
// => http://localhost:3000/prefix/css/style.css
app.Static("*", "./public/index.html")
// => http://localhost:3000/any/path/shows/index/html
log.Fatal(app.Listen(":3000"))
}
```
#### 📖 [**Middleware & Next**](https://docs.gofiber.io/api/ctx#next)
```go
func main() {
app := fiber.New()
// Bütün routelara etki eder.
app.Use(func(c *fiber.Ctx) error {
fmt.Println("🥇 İlk handler")
return c.Next()
})
// /api ile başlayan bütün routelara etki eder.
app.Use("/api", func(c *fiber.Ctx) error {
fmt.Println("🥈 İkinci handler")
return c.Next()
})
// GET /api/register
app.Get("/api/list", func(c *fiber.Ctx) error {
fmt.Println("🥉 Son handler")
return c.SendString("Merhaba, Dünya 👋!")
})
log.Fatal(app.Listen(":3000"))
}
```
📚 Daha fazla kod örneği göster
### Views Engines
📖 [Config](https://docs.gofiber.io/api/fiber#config)
📖 [Engines](https://github.com/gofiber/template)
📖 [Render](https://docs.gofiber.io/api/ctx#render)
Hiçbir View Engine ayarlanmadığında Fiber varsayılan olarak [html/template'a](https://golang.org/pkg/html/template/) geçer.
Kısmi yürütmek istiyorsanız veya [amber](https://github.com/eknkc/amber), [handlebars](https://github.com/aymerick/raymond), [mustache](https://github.com/cbroglie/mustache) veya [pug](https://github.com/Joker/jade) gibi farklı engine'ler kullanmak istiyorsanız
Çoklu View Engine destekleyen [Template'ımıza](https://github.com/gofiber/template göz atın.
```go
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/pug"
)
func main() {
// Uygulamayı başlatmadan önce View Engine tanımlayabilirsiniz:
app := fiber.New(fiber.Config{
Views: pug.New("./views", ".pug"),
})
// Ve şimdi `./views/home.pug` templateni şu şekilde çağırabilirsiniz:
app.Get("/", func(c *fiber.Ctx) error {
return c.Render("home", fiber.Map{
"title": "Homepage",
"year": 1999,
})
})
log.Fatal(app.Listen(":3000"))
}
```
### Routeları Zincirler Halinde Gruplama
📖 [Group](https://docs.gofiber.io/api/app#group)
```go
func middleware(c *fiber.Ctx) error {
fmt.Println("Beni umursama!")
return c.Next()
}
func handler(c *fiber.Ctx) error {
return c.SendString(c.Path())
}
func main() {
app := fiber.New()
// Root API route
api := app.Group("/api", middleware) // /api
// API v1 routeları
v1 := api.Group("/v1", middleware) // /api/v1
v1.Get("/list", handler) // /api/v1/list
v1.Get("/user", handler) // /api/v1/user
// API v2 routeları
v2 := api.Group("/v2", middleware) // /api/v2
v2.Get("/list", handler) // /api/v2/list
v2.Get("/user", handler) // /api/v2/user
// ...
}
```
### Middleware Loglama (Logger)
📖 [Logger](https://docs.gofiber.io/api/middleware/logger)
```go
package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func main() {
app := fiber.New()
app.Use(logger.New())
// ...
log.Fatal(app.Listen(":3000"))
}
```
### Farklı Originler Arası Kaynak Paylaşımı (CORS)
📖 [CORS](https://docs.gofiber.io/api/middleware/cors)
```go
import (
"log"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
app := fiber.New()
app.Use(cors.New())
// ...
log.Fatal(app.Listen(":3000"))
}
```
`Origin` başlığı içinde herhangi bir alan adı kullanarak CORS'u kontrol edin:
```bash
curl -H "Origin: http://example.com" --verbose http://localhost:3000
```
### Özelleştirilebilir 404 yanıtları
📖 [HTTP Methodları](https://docs.gofiber.io/api/ctx#status)
```go
func main() {
app := fiber.New()
app.Static("/", "./public")
app.Get("/demo", func(c *fiber.Ctx) error {
return c.SendString("Bu bir demodur!")
})
app.Post("/register", func(c *fiber.Ctx) error {
return c.SendString("Hoşgeldiniz!")
})
// Hiçbir endpointle eşleşmezse gideceği middleware ve yanıtı.
app.Use(func(c *fiber.Ctx) error {
return c.SendStatus(404)
// => 404 "Sayfa bulunamadı"
})
log.Fatal(app.Listen(":3000"))
}
```
### JSON Yanıtları
📖 [JSON](https://docs.gofiber.io/ctx#json)
```go
type User struct {
Isim string `json:"name"`
Yas int `json:"age"`
}
func main() {
app := fiber.New()
app.Get("/user", func(c *fiber.Ctx) error {
return c.JSON(&User{"Muhittin Topalak", 20})
// => {"Isim":"Muhittin Topalak", "Yas":20}
})
app.Get("/json", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"success": true,
"mesaj": "Merhaba Muhittin Topalak!",
})
// => {"success":true, "message":"Merhaba Muhittin Topalak!"}
})
log.Fatal(app.Listen(":3000"))
}
```
### WebSocket Yükseltmesi
📖 [Websocket](https://github.com/gofiber/websocket)
```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/websocket"
)
func main() {
app := fiber.New()
app.Get("/ws", websocket.New(func(c *websocket.Conn) {
for {
mt, msg, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
break
}
log.Printf("recv: %s", msg)
err = c.WriteMessage(mt, msg)
if err != nil {
log.Println("write:", err)
break
}
}
}))
log.Fatal(app.Listen(":3000"))
// ws://localhost:3000/ws
}
```
### Middleware Kurtarıcısı
📖 [Recover](https://docs.gofiber.io/api/middleware/recover)
```go
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/recover"
)
func main() {
app := fiber.New()
app.Use(recover.New())
app.Get("/", func(c *fiber.Ctx) error {
panic("normalde bu uygulamanızı çökertir.")
})
log.Fatal(app.Listen(":3000"))
}
```
## 🧬 Dahili Middlewarelar
Fibera dahil edilen middlewareların bir listesi aşağıda verilmiştir.
| Middleware | Açıklama |
| :------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [basicauth](https://github.com/gofiber/fiber/tree/master/middleware/basicauth) | Basic auth middleware'i, bir HTTP Basic auth sağlar. Geçerli kimlik bilgileri için sonraki handlerı ve eksik veya geçersiz kimlik bilgileri için 401 döndürür. |
| [compress](https://github.com/gofiber/fiber/tree/master/middleware/compress) | Fiber için sıkıştırma middleware, varsayılan olarak `deflate`, `gzip` ve `brotli`yi destekler. |
| [cache](https://github.com/gofiber/fiber/tree/master/middleware/cache) | Reponseları durdur ve önbelleğe al |
| [cors](https://github.com/gofiber/fiber/tree/master/middleware/cors) | Çeşitli seçeneklerle başlangıçlar arası kaynak paylaşımını \(CORS\) etkinleştirin. |
| [csrf](https://github.com/gofiber/fiber/tree/master/middleware/csrf) | CSRF exploitlerinden korunun. |
| [filesystem](https://github.com/gofiber/fiber/tree/master/middleware/filesystem) | Fiber için FileSystem middleware, Alireza Salary'e özel teşekkürler |
| [favicon](https://github.com/gofiber/fiber/tree/master/middleware/favicon) | Bir dosya yolu sağlanmışsa, loglardaki favicon'u yoksayar veya bellekten sunar. |
| [limiter](https://github.com/gofiber/fiber/tree/master/middleware/limiter) | Fiber için hız sınırlayıcı middleware'i. Açık API'lere ve/veya parola sıfırlama gibi endpointlere yönelik tekrarlanan istekleri sınırlamak için kullanın. |
| [logger](https://github.com/gofiber/fiber/tree/master/middleware/logger) | HTTP istek/yanıt logger'ı. |
| [pprof](https://github.com/gofiber/fiber/tree/master/middleware/pprof) | Matthew Lee'ye özel teşekkürler \(@mthli\) |
| [proxy](https://github.com/gofiber/fiber/tree/master/middleware/proxy) | Birden çok sunucuya proxy istekleri yapmanızı sağlar |
| [requestid](https://github.com/gofiber/fiber/tree/master/middleware/requestid) | Her requeste id verir |
| [recover](https://github.com/gofiber/fiber/tree/master/middleware/recover) | Recover middleware'i, stack chain'ini herhangi bir yerindeki paniklerden kurtulur ve kontrolü merkezileştirilmiş [ErrorHandler'e](https://docs.gofiber.io/guide/error-handling) verir. |
| [timeout](https://github.com/gofiber/fiber/tree/master/middleware/timeout) | Bir request için maksimum süre ekler ve aşılırsa ErrorHandler'a iletir. |
## 🧬 Harici Middlewarelar
Harici olarak barındırılan middlewareların modüllerinin listesi [Fiber ekibi](https://github.com/orgs/gofiber/people) tarafından korunur.
| Middleware | Açıklama |
| :------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [adaptor](https://github.com/gofiber/adaptor) | Fiber request handlerdan net/http handlerları için dönüştürücü, @arsmn'a özel teşekkürler! |
| [helmet](https://github.com/gofiber/helmet) | Çeşitli HTTP headerları ayarlayarak uygulamalarınızın güvenliğini sağlamaya yardımcı olur. |
| [jwt](https://github.com/gofiber/jwt) | JWT, bir JSON Web Token \(JWT\) yetkilendirmesi döndüren middleware. |
| [keyauth](https://github.com/gofiber/keyauth) | Key auth middleware, key tabanlı bir authentication sağlar. |
| [rewrite](https://github.com/gofiber/rewrite) | Rewrite middleware, sağlanan kurallara göre URL yolunu yeniden yazar. Geriye dönük uyumluluk için veya yalnızca daha temiz ve daha açıklayıcı bağlantılar oluşturmak için yardımcı olabilir. |
| [session](https://github.com/gofiber/session) | Bu session middleware'i, @savsgio MIT tarafından fasthttp/session üzerine inşa edilmiştir. Bu middleware'a yardımcı olduğu için @thomasvvugt'a özel teşekkürler. |
| [template](https://github.com/gofiber/template) | Bu paket, Fiber `v1.10.x`, Go sürüm 1.13 veya üzeri gerekli olduğunda kullanılabilecek 8 template engine içerir. |
| [websocket](https://github.com/gofiber/websocket) | Yereller desteğiyle Fiber için Fasthttp WebSocket'a dayalıdır! |
## 🌱 Üçüncü Parti Middlewarelar
Bu, Fiber topluluğu tarafından oluşturulan middleware'lerin bir listesidir, sizinkini görmek istiyorsanız lütfen bir PR oluşturun!
- [arsmn/fiber-casbin](https://github.com/arsmn/fiber-casbin)
- [arsmn/fiber-introspect](https://github.com/arsmn/fiber-introspect)
- [arsmn/fiber-swagger](https://github.com/arsmn/fiber-swagger)
- [arsmn/gqlgen](https://github.com/arsmn/gqlgen)
- [codemicro/fiber-cache](https://github.com/codemicro/fiber-cache)
- [sujit-baniya/fiber-boilerplate](https://github.com/sujit-baniya/fiber-boilerplate)
- [juandiii/go-jwk-security](https://github.com/juandiii/go-jwk-security)
- [kiyonlin/fiber_limiter](https://github.com/kiyonlin/fiber_limiter)
- [shareed2k/fiber_limiter](https://github.com/shareed2k/fiber_limiter)
- [shareed2k/fiber_tracing](https://github.com/shareed2k/fiber_tracing)
- [thomasvvugt/fiber-boilerplate](https://github.com/thomasvvugt/fiber-boilerplate)
- [ansrivas/fiberprometheus](https://github.com/ansrivas/fiberprometheus)
- [LdDl/fiber-long-poll](https://github.com/LdDl/fiber-long-poll)
- [K0enM/fiber_vhost](https://github.com/K0enM/fiber_vhost)
- [theArtechnology/fiber-inertia](https://github.com/theArtechnology/fiber-inertia)
- [aschenmaker/fiber-health-check](https://github.com/aschenmaker/fiber-health-check)
- [elastic/apmfiber](https://github.com/elastic/apm-agent-go/tree/master/module/apmfiber)
## 👍 Destek
Eğer **teşekkür etmek** veya `Fiber`'ın aktif geliştirilmesini desteklemek istiyorsanız:
1. Projeye [yıldız](https://github.com/gofiber/fiber/stargazers) verebilirsiniz.
2. [Twitter hesabınızdan](https://twitter.com/intent/tweet?text=Fiber%20is%20an%20Express%20inspired%20%23web%20%23framework%20built%20on%20top%20of%20Fasthttp%2C%20the%20fastest%20HTTP%20engine%20for%20%23Go.%20Designed%20to%20ease%20things%20up%20for%20%23fast%20development%20with%20zero%20memory%20allocation%20and%20%23performance%20in%20mind%20%F0%9F%9A%80%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber) proje hakkında tweet atabilirsinşz.
3. [Medium](https://medium.com/), [Dev.to](https://dev.to/) veya kişisel blogunuz üzerinden bir inceleme veya eğitici yazı yazabilirsiniz.
4. Projeye [bir fincan kahve](https://buymeacoff.ee/fenny) ısmarlayarak destek olabilirsiniz.
## ☕ Destekçiler
Fiber; alan adı, gitbook, netlify, serverless yer sağlayıcısı giderleri ve benzeri şeyleri ödemek için bağışlarla yaşayan bir açık kaynaklı projedir. Eğer Fiber'e destek olmak isterseniz, ☕ [**buradan kahve ısmarlayabilirsiniz**](https://buymeacoff.ee/fenny).
| | User | Donation |
| :--------------------------------------------------------- | :----------------------------------------------- | :------- |
|  | [@destari](https://github.com/destari) | ☕ x 10 |
|  | [@dembygenesis](https://github.com/dembygenesis) | ☕ x 5 |
|  | [@thomasvvugt](https://github.com/thomasvvugt) | ☕ x 5 |
|  | [@hendratommy](https://github.com/hendratommy) | ☕ x 5 |
|  | [@ekaputra07](https://github.com/ekaputra07) | ☕ x 5 |
|  | [@jorgefuertes](https://github.com/jorgefuertes) | ☕ x 5 |
|  | [@candidosales](https://github.com/candidosales) | ☕ x 5 |
|  | [@l0nax](https://github.com/l0nax) | ☕ x 3 |
|  | [@ankush](https://github.com/ankush) | ☕ x 3 |
|  | [@bihe](https://github.com/bihe) | ☕ x 3 |
|  | [@justdave](https://github.com/justdave) | ☕ x 3 |
|  | [@koddr](https://github.com/koddr) | ☕ x 1 |
|  | [@lapolinar](https://github.com/lapolinar) | ☕ x 1 |
|  | [@diegowifi](https://github.com/diegowifi) | ☕ x 1 |
|  | [@ssimk0](https://github.com/ssimk0) | ☕ x 1 |
|  | [@raymayemir](https://github.com/raymayemir) | ☕ x 1 |
|  | [@melkorm](https://github.com/melkorm) | ☕ x 1 |
|  | [@marvinjwendt](https://github.com/thomasvvugt) | ☕ x 1 |
|  | [@toishy](https://github.com/toishy) | ☕ x 1 |
## 💻 Koda Katkı Sağlayanlar
## ⭐️ Projeyi Yıldızlayanlar
## ⚠️ Lisans
Telif (c) 2019-günümüz [Fenny](https://github.com/fenny) ve [Contributors](https://github.com/gofiber/fiber/graphs/contributors). `Fiber`, [MIT Lisansı](https://github.com/gofiber/fiber/blob/master/LICENSE) altında özgür ve açık kaynaklı bir yazılımdır. Resmi logosu [Vic Shóstak](https://github.com/koddr) tarafında tasarlanmıştır ve [Creative Commons](https://creativecommons.org/licenses/by-sa/4.0/) lisansı altında dağıtımı yapılır. (CC BY-SA 4.0 International).
**Üçüncü Parti Library Lisansları**
- [schema](https://github.com/gorilla/schema/blob/master/LICENSE)
- [isatty](https://github.com/mattn/go-isatty/blob/master/LICENSE)
- [fasthttp](https://github.com/valyala/fasthttp/blob/master/LICENSE)
- [encoding](https://github.com/segmentio/encoding/blob/master/LICENSE)
- [colorable](https://github.com/mattn/go-colorable/blob/master/LICENSE)
- [fasttemplate](https://github.com/valyala/fasttemplate/blob/master/LICENSE)
- [bytebufferpool](https://github.com/valyala/bytebufferpool/blob/master/LICENSE)
- [gopsutil](https://github.com/shirou/gopsutil/blob/master/LICENSE)
- [go-ole](https://github.com/go-ole/go-ole)
- [wmi](https://github.com/StackExchange/wmi)