完善的 Go 路由工具 mux

码农软件 · 软件分类 · 正则表达式工具 · 2019-10-08 23:44:19

软件介绍

mux 是对 http.ServeMux 的扩展,添加正则路由等功能。

相对于 http.ServeMux 提供了以下功能: 

  1. 正则路由;

  2. 自动生成 OPTIONS;

通过与 handlers 还可以实现诸如按域名过滤等功能。

m := mux.NewServerMux(false).
    Get("/user/1", h).              // GET /user/1
    Post("/api/login", h).          // POST /api/login
    Get("/blog/post/{id:\\d+}", h). // GET /blog/post/{id:\d+} 正则路由
    Options("/user/1", "GET")       // OPTIONS /user/1 手动指定该路由项的 OPTIONS 请求方法返回内容

// 统一前缀名称的路由
p := m.Prefix("/api")
p.Get("/logout", h) // 相当于m.Get("/api/logout", h)
p.Post("/login", h) // 相当于m.Get("/api/login", h)

http.ListenAndServe("8080", m)

安装

go get github.com/issue9/mux

本文地址:https://codercto.com/soft/d/16347.html

Mastering Flask

Mastering Flask

Jack Stouffer / Packt Publishing / 2015-9-30 / USD 49.99

Work with scalable Flask application structures to create complex web apps Discover the most powerful Flask extensions and learn how to create one Deploy your application to real-world platforms......一起来看看 《Mastering Flask》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

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

UNIX 时间戳转换