Skip to content

Latest commit

 

History

History
153 lines (100 loc) · 4.94 KB

README_CH.md

File metadata and controls

153 lines (100 loc) · 4.94 KB

🚀 Fiber en ru

GitHub license Join the chat at https://gitter.im/gofiber/community

Fiber logo

Fiber 是一个 Express.js 运行的样式化HTTP Web框架实现 Fasthttp, 最快的 HTTP引擎 Go (Golang). 该软件包使用了相似的框架约定 Express.

人们从 Node.jsGo 通常会遇到学习曲线不好的问题,从而开始构建他们的Web应用程序, 这个项目是为了 缓解 事情准备 快速 发展,但与 零内存分配性能 心里.

API Documentation

📚 我们创建了一个扩展我们创建了一个扩展 API documentation (包括例子), 点击这里.

Benchmark

👉 点击这里 查看所有基准测试结果.

Features

  • 针对速度和低内存使用进行了优化
  • 快速的服务器端编程
  • 通过参数轻松路由
  • 具有自定义前缀的静态文件
  • 具有Next支持的中间件
  • Express API端点
  • Extended documentation

Installing

假设您已经安装 Go 1.11+ 😉

安装 Fiber 通过调用以下命令来打包:

go get -u github.com/gofiber/fiber

Hello, world!

本质上,下面嵌入是您可以创建的最简单的Fiber应用程序:

// server.go

package main

import "github.com/gofiber/fiber"

func main() {
  // Create new Fiber instance
  app := fiber.New()

  // Create new route with GET method
  app.Get("/", func(c *fiber.Ctx) {
    c.Send("Hello, World!")
  })

  // Start server on http://localhost:8080
  app.Listen(8080)
}

转到控制台并运行:

go run server.go

现在,浏览至 http://localhost:8080 你应该看到 Hello, World! 在页面上! 🎉

Static files

要提供静态文件,请使用 Static 方法:

package main

import "github.com/gofiber/fiber"

func main() {
  // Create new Fiber instance
  app := fiber.New()

  // Serve all static files on ./public folder
  app.Static("./public")

  // Start server on http://localhost:8080
  app.Listen(8080)
}

现在,您可以加载公共目录中的文件:

http://localhost:8080/hello.html
http://localhost:8080/js/script.js
http://localhost:8080/css/style.css

Middleware

中间件从未如此简单!就像Express,您致电 Next() 匹配路线功能:

package main

import "github.com/gofiber/fiber"

func main() {
  // Create new Fiber instance
  app := fiber.New()

  // Define all used middlewares in Use()

  app.Use(func(c *fiber.Ctx) {
    c.Write("Match anything!\n")
    c.Next()
  })

  app.Use("/api", func(c *fiber.Ctx) {
    c.Write("Match starting with /api\n")
    c.Next()
  })

  app.Get("/api/user", func(c *fiber.Ctx) {
    c.Write("Match exact path /api/user\n")
  })

  // Start server on http://localhost:8080
  app.Listen(8080)
}

Project assistance

如果您要说声谢谢或/并且支持积极的发展 gofiber/fiber:

  1. 将GitHub Star添加到项目中。
  2. 关于项目的推文 on your Twitter.
  3. 帮助我们翻译 READMEAPI Docs 换一种语言.

谢谢你的支持! 😘 我们在一起 Fiber Web Framework 每天都好.

Stargazers over time

Stargazers over time

License

⚠️ 请注意: gofiber/fiber 是根据以下条款获得许可的免费开源软件 MIT License.