???? Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp, the...

栏目: IT技术 · 发布时间: 4年前

:electric_plug: Fiber Web Framework ???? Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp, the... ???? Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp, the...

???? Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp, the...

Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp , the fastest HTTP engine for Go (Golang). The package make use of similar framework convention as they are in Express.

People switching from Node.js to Go often end up in a bad learning curve to start building their webapps, this project is meant to ease things up for fast development, but with zero memory allocation and performance in mind.

API Documentation

:books: We created an extended API documentation ( including examples ), click here .

Benchmark

???? Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp, the...

:point_right: Click here to see all benchmark results.

Features

  • Optimized for speed and low memory usage
  • Rapid Server-Side Programming
  • Easy routing with parameters
  • Static files with custom prefix
  • Middleware with Next support
  • Express API endpoints
  • Extended documentation

Installing

Assuming you’ve already installed Go 1.11+ :wink:

Install the Fiber package by calling the following command:

go get -u github.com/gofiber/fiber

Hello, world!

Embedded below is essentially the simplest Fiber app you can create:

// 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 to console and run:

go run server.go

And now, browse to http://localhost:8080 and you should see Hello, World! on the page! :tada:

Static files

To serve static files, use the Static method:

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

Now, you can load the files that are in the public directory:

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

Middleware

Middleware has never been so easy! Just like Express you call the Next() matching route function:

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

If you want to say «thank you» or/and support active development gofiber/fiber :

  1. Add a GitHub Star to project.
  2. Help us to translate this README and API Docs to another language.

Thanks for your support! :kissing_heart: Together, we make Fiber Web Framework better every day.

Stargazers over time

License

:warning: Please note: gofiber/fiber is free and open-source software licensed under the MIT License .


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Spark技术内幕

Spark技术内幕

张安站 / 机械工业出版社 / 2015-9-1

Spark是不断壮大的大数据分析解决方案家族中备受关注的新增成员。它不仅为分布式数据集的处理提供一个有效框架,而且以高效的方式处理分布式数据集。它支持实时处理、流处理和批处理,提供了AllinOne的统一解决方案,使得Spark极具竞争力。 本书以源码为基础,深入分析Spark内核的设计理念和架构实现,系统讲解各个核心模块的实现,为性能调优、二次开发和系统运维提供理论支持;本文最后以项目实战......一起来看看 《Spark技术内幕》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换