1 Star 0 Fork 0

视迅速达/fiberDemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
陈圣文 提交于 2021-02-19 15:40 . auto commit by deploy
package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"log"
)
var Version string
func init() {
Version = "1.0.2"
}
func main() {
app := fiber.New()
// GET /
app.Get("/", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("Hello, World! -- %s", Version)
return c.SendString(msg)
})
// GET /john
app.Get("/:name", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("Hello, %s 👋!", c.Params("name"))
return c.SendString(msg) // => Hello john 👋!
})
// GET /john/75
app.Get("/:name/:age/:gender?", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("👴 %s is %s years old", c.Params("name"), c.Params("age"))
return c.SendString(msg) // => 👴 john is 75 years old
})
// GET /dictionary.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) // => 📃 dictionary.txt
})
// GET /flights/LAX-SFO
app.Get("/flights/:from-:to", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("💸 From: %s, To: %s", c.Params("from"), c.Params("to"))
return c.SendString(msg) // => 💸 From: LAX, To: SFO
})
// GET /api/register
app.Get("/api/*", func(c *fiber.Ctx) error {
msg := fmt.Sprintf("✋ %s", c.Params("*"))
return c.SendString(msg) // => ✋ register
})
log.Fatal(app.Listen(":8000"))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/subowen_admin/fiber_demo.git
git@gitee.com:subowen_admin/fiber_demo.git
subowen_admin
fiber_demo
fiberDemo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385