fiber/.github/README_tr.md
2020-02-21 16:54:14 +01:00

11 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)
}

⚙️ 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 github.com/gofiber/fiber

🤖 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.

🎯 Ö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 depomuzu veya API dökümantasyonunu ziyaret ediniz.

Rotalar

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

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

  // GET /john
  app.Get("/:name/:age?", func(c *fiber.Ctx) {
    fmt.Printf("Name: %s, Age: %s", c.Params("name"), c.Params("age"))
    // => Name: john, Age:
  })

  // GET /api/register
  app.Get("/api*", func(c *fiber.Ctx) {
    fmt.Printf("/api%s", c.Params("*"))
    // => /api/register
  })

  app.Listen(3000)
}

Statik dosya yönetimi

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 & Sonraki

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

  // Match any route
  app.Use(func(c *fiber.Ctx) {
    fmt.Println("First middleware")
    c.Next()
  })

  // Match all routes starting with /api
  app.Use("/api", func(c *fiber.Ctx) {
    fmt.Println("Second middleware")
    c.Next()
  })

  // POST /api/register
  app.Post("/api/register", func(c *fiber.Ctx) {
    fmt.Println("Last middleware")
    c.Send("Hello, World!")
  })

  app.Listen(3000)
}
📚 Daha fazla kod örneği görüntüle

Özel 404 Cevabı

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!")
  })

  // Last middleware to match anything
  app.Use(func(c *fiber.Ctx) {
    c.SendStatus(404) // => 404 "Not Found"
  })

  app.Listen(3000)
}

JSON Cevabı

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

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

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

  app.Listen(3000)
}

Panikten Kurtarma

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

  app.Get("/", func(c *fiber.Ctx) {
    panic("Something went wrong!")
  })

  app.Recover(func(c *fiber.Ctx) {
    c.Status(500).Send(c.Error())
    // => 500 "Something went wrong!"
  })

  app.Listen(3000)
}

💬 Medya

👍 Destek

Eğer teşekkür etmek ve/veya Fiber ın 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. Bu BENİOKU sayfasını başka bir dile tercüme etmek için bize yardım edin.

Destekleyenler

Bir Kahve Ismarla

HenrikBinggl

Vic Shóstak

MarvinJWendt

ToishY

Yıldızlar

Zamana göre yıldız sayısı

⚠️ Lisans

Fiber MIT Lisansı kapsamında ücretsiz ve açık kaynak kodlu bir yazılımdır.