完善的 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

Creative Selection

Creative Selection

Ken Kocienda / St. Martin's Press / 2018-9-4 / USD 28.99

Hundreds of millions of people use Apple products every day; several thousand work on Apple's campus in Cupertino, California; but only a handful sit at the drawing board. Creative Selection recounts ......一起来看看 《Creative Selection》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试