1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-23 21:24:02 +00:00
fiber/.github/README_tr.md

31 KiB
Raw Blame History

Fiber

Fiber, Go için en hızlı HTTP motoru olan Fasthttp üzerine inşa edilmiş, Express den ilham alan bir web çatısıdır. Sıfır bellek ayırma ve performans göz önünde bulundurularak hızlı geliştirme için işleri kolaylaştırmak üzere tasarlandı.

Hızlı Başlangıç

package main

import "github.com/gofiber/fiber"

func main() {
  app := fiber.New()

  app.Get("/", func(c *fiber.Ctx) {
    c.Send("Merhaba dünya!")
  })

  app.Listen(3000)
}

🤖 Performans Ölçümleri

Bu testler TechEmpower ve Go Web ile koşuldu. Bütün sonuçları görmek için lütfen Wiki sayfasını ziyaret ediniz.

⚙️ Kurulum

İlk önce, Go yu indirip kuruyoruz. 1.11 veya daha yeni sürüm gereklidir.

go get komutunu kullanarak kurulumu tamamlıyoruz:

go get -u github.com/gofiber/fiber/...

🎯 Özellikler

💡 Felsefe

Node.js den Go ya geçen yeni gopher lar kendi web uygulamalarını ve mikroservislerini yazmaya başlamadan önce dili öğrenmek ile uğraşıyorlar. Fiber, bir web çatısı olarak, minimalizm ve UNIX yolunu izlemek fikri ile oluşturuldu. Böylece yeni gopher lar sıcak ve güvenilir bir hoşgeldin ile Go dünyasına giriş yapabilirler.

Fiber internet üzerinde en popüler olan Express web çatısından 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.

👀 Örnekler

Aşağıda yaygın örneklerden bazıları listelenmiştir. Daha fazla kod örneği görmek için, lütfen Kod deposunu veya API dökümantasyonunu ziyaret ediniz.

Rotalama

📖 Rotalama

func main() {
  app := fiber.New()

  // GET /john http methodunu çağır
  app.Get("/:name", func(c *fiber.Ctx) {
    fmt.Printf("Hello %s!", c.Params("name"))
    // => Hello john!
  })

  // GET /john http methodunu çağır
  app.Get("/:name/:age?", func(c *fiber.Ctx) {
    fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
    // => Name: john, Age:
  })
  
  // GET /plantae/prunus.persica
  app.Get("/plantae/:genus.:species", func(c *fiber.Ctx) {
    fmt.Printf("Genius: %s, Species: %s", c.Params("genus"), c.Params("species"))
    // => Genius: prunus, Species: persica
  })

  // GET /flights/LAX-SFO
  app.Get("/flights/:from-:to", func(c *fiber.Ctx) {
    fmt.Printf("From: %s, To: %s", c.Params("from"), c.Params("to"))
    // => From: LAX, To: SFO
  })

  // GET /api/register http methodunu çağır
  app.Get("/api/*", func(c *fiber.Ctx) {
    fmt.Printf("/api/%s", c.Params("*"))
    // => /api/register
  })

  app.Listen(3000)
}

Statik Dosyaları Servis Etmek

📖 Statik

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

  app.Listen(3000)
}

Ara Katman ve İleri(Middleware & Next)

📖 Ara Katman 📖 İleri

func main() {
  app := fiber.New()

  // Bütün rotalarla eşleş
  app.Use(func(c *fiber.Ctx) {
    fmt.Println("First middleware")
    c.Next()
  })

  // /api ile başlayan tüm rotalarla eşleş
  app.Use("/api", func(c *fiber.Ctx) {
    fmt.Println("Second middleware")
    c.Next()
  })

  // GET /api/register http methodunu çağır
  app.Get("/api/list", func(c *fiber.Ctx) {
    fmt.Println("Last middleware")
    c.Send("Hello, World!")
  })

  app.Listen(3000)
}
📚 Daha fazla kod örneği göster

Views engines

📖 Settings
📖 Engines
📖 Render

Fiber defaults to the html/template when no view engine is set.

If you want to execute partials or use a different engine like amber, handlebars, mustache or pug etc..

Checkout our Template package that support multiple view engines.

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/template/pug"
)

func main() {
  // You can setup Views engine before initiation app:
  app := fiber.New(&fiber.Settings{
    Views: pug.New("./views", ".pug"),
  })

  // OR after initiation app at any convenient location:
  app.Settings.Views = pug.New("./views", ".pug"),

  // And now, you can call template `./views/home.pug` like this:
  app.Get("/", func(c *fiber.Ctx) {
    c.Render("home", fiber.Map{
      "title": "Homepage",
      "year":  1999,
    })
  })

  // ...
}

Rotaları Zincirlere Gruplama

📖 Grup

func main() {
  app := fiber.New()

  // Kök API rotası
  api := app.Group("/api", cors())  // /api

  // API v1 rotası
  v1 := api.Group("/v1", mysql())   // /api/v1
  v1.Get("/list", handler)          // /api/v1/list
  v1.Get("/user", handler)          // /api/v1/user

  // API v2 rotası
  v2 := api.Group("/v2", mongodb()) // /api/v2
  v2.Get("/list", handler)          // /api/v2/list
  v2.Get("/user", handler)          // /api/v2/user

  // ...
}

Ara Katman Günlükcüsü(Logger)

📖 Günlükcü

import (
    "github.com/gofiber/fiber"
    "github.com/gofiber/logger"
)

func main() {
    app := fiber.New()

    // Tercihe bağlı günlük ayarları
    config := logger.Config{
      Format:     "${time} - ${method} ${path}\n",
      TimeFormat: "Mon, 2 Jan 2006 15:04:05 MST",
    }

    // Günlükcüyü ayarla
    app.Use(logger.New(config))

    app.Listen(3000)
}

Farklı Merkezler Arası Kaynak Paylaşımı (CORS)

📖 CORS

import (
    "github.com/gofiber/fiber"
    "github.com/gofiber/cors"
)

func main() {
    app := fiber.New()

    // Varsayılan ayarlarla CORS
    app.Use(cors.New())

    app.Listen(3000)
}

Origin başlığı içinde herhangı bir alan adı kullanarak CORS'u kontrol et:

curl -H "Origin: http://example.com" --verbose http://localhost:3000

Özelleştirilebilir 404 yanıtları

📖 HTTP Methodlari

func main() {
  app := fiber.New()

  app.Static("./public")

  app.Get("/demo", func(c *fiber.Ctx) {
    c.Send("This is a demo!")
  })

  app.Post("/register", func(c *fiber.Ctx) {
    c.Send("Welcome!")
  })

  // Herhangi bir şeyle eşleşen son ara katman
  app.Use(func(c *fiber.Ctx) {
    c.SendStatus(404)
    // => 404 "Not Found"
  })

  app.Listen(3000)
}

JSON Yanıtları

📖 JSON

type User struct {
  Name string `json:"name"`
  Age  int    `json:"age"`
}

func main() {
  app := fiber.New()

  app.Get("/user", func(c *fiber.Ctx) {
    c.JSON(&User{"John", 20})
    // => {"name":"John", "age":20}
  })

  app.Get("/json", func(c *fiber.Ctx) {
    c.JSON(fiber.Map{
      "success": true,
      "message": "Hi John!",
    })
    // => {"success":true, "message":"Hi John!"}
  })

  app.Listen(3000)
}

WebSocket Yükseltmesi

📖 Websocket

import (
    "github.com/gofiber/fiber"
    "github.com/gofiber/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
      }
    }
  }))

  app.Listen(3000)
  // ws://localhost:3000/ws
}

Ara Katman'dan Kurtarma

📖 Kurtar

import (
    "github.com/gofiber/fiber"
    "github.com/gofiber/recover"
)

func main() {
  app := fiber.New()

  // Özelleştirilebilir kurtarma ayarı
  config := recover.Config{
    Handler: func(c *fiber.Ctx, err error) {
			c.SendString(err.Error())
			c.SendStatus(500)
		},
  }

  // Özelleştrilebilir günlükleme
  app.Use(recover.New(config))

  app.Listen(3000)
}

🧬 Official Middlewares

For an more maintainable middleware ecosystem, we've put official middlewares into separate repositories:

🌱 Third Party Middlewares

This is a list of middlewares that are created by the Fiber community, please create a PR if you want to see yours!

💬 Medya

👍 Destek

Eğer teşekkür etmek ve/veya Fiber'in aktif geliştirilmesini desteklemek istiyorsanız:

  1. Projeye GitHub Yıldızı verin.
  2. Twitter hesabınızdan proje hakkında tweet atın.
  3. Medium, Dev.to veya kişisel blog üzerinden bir inceleme veya eğitici yazı yazın.
  4. API dökümantasyonunu çevirerek destek olabilirsiniz Crowdin Crowdin
  5. Projeye [bir fincan kahve] ısmarlayarak projeye destek olabilirsiniz(https://buymeacoff.ee/fenny).

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.

User Donation
@thomasvvugt x 5
@hendratommy x 5
@ekaputra07 x 5
@jorgefuertes x 5
@candidosales x 5
@l0nax x 3
@ankush x 3
@bihe x 3
@justdave x 3
@koddr x 1
@lapolinar x 1
@diegowifi x 1
@ssimk0 x 1
@raymayemir x 1
@melkorm x 1
@marvinjwendt x 1
@toishy x 1

💻 Koda Katkı Sağlayanlar

Code Contributors

Stargazers

Stargazers over time

⚠️ Lisans

Telif (c) 2019-günümüz Fenny ve Contributors. Fiber, MIT Lisansı altında özgür ve açık kaynaklı bir yazılımdır. Resmi logosu Vic Shóstak tarafında tasarlanmıştır ve Creative Commons lisansı altında dağıtımı yapılır. (CC BY-SA 4.0 International).

3. Parti yazılım lisanları