beego/mux — 483★ trên GitHub (Go). A high performance and powerful trie based url path router for Go.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
A high performance and powerful trie based url path router for Go.
This router supports fixed and regex rules in routing pattern, and matches request method. It's optimized by trie structure for faster matching and large scale rules.
requirement: Go 1.7+
Feature
todo
Usage
This is a simple example for mux. Read godoc to get full api documentation.
The routing pattern can set as fixed pattern as most simple way. When using fixed pattern, it supports to parse json, xml and html extension to match pattern.
But in common cases, you need parameters to match differenct segments in path.
Named parameters
As you see, :id is a named parameter. The matched parameters can read one via mux.Param method from *http.Request by parameter's name.
// r is *http.Request
fmt.Println(mux.Param(r,":id"))
Or read all parameters by mux.Params.
// r is *http.Request
fmt.Println(mux.Params(r))
// e.g. map[:id:1 :name:beego]
A named parameter only can match single segment of path with extension.
Pattern: /abc/:id
/abc/ no match
/abc/123 matched (:id is 123)
/abc/xyz matched (:id is xyz)
/abc/123/xyz no matched
/abc/123.html matched (:id is 123.html)
Wildcard parameters
If you need to match several segments in path, use * and *.* named wildcard parameters.
* matches all segments between previous and next segment node in pattern. The matched segement parts are stored in params with key :splat.
Pattern: /abc/*/xyz
/abc/xyz no match
/abc/123/xyz matched (:splat is 123)
/abc/12/34/xyz matched (:splat is 12/34)
*.* has familar behaviour with *, but matched results are two parts, :path as path segment and :ext as extension suffix.
Pattern : /abc/*.*
/abc/xyz.json matched (:path is xyz, :ext is json)
/abc/123/xyz.html matched (:path is 123/xyz, :ext is html)
Regexp parameters
mux supports a regular expression as a paramter , named regexp paramaters. You can set a regexp into pattern with a name placeholder.
Pattern : /abc/:id([0-9]+)
/abc/123 matched (:id is 123)
/abc/xyz no matched
You can set value type for one named paramater to simplify some common regexp rules. Now support :int ([0-9]+) and :string ([\w]+).
Pattern: /abc/:id:int
/abc/123 matched (:id is 123)
/abc/xyz no match
Regexp paramters can match several parts in one segment in path.
Pattern: /abc/article_:id:int
/abc/123 no matched
/abc/article_123 matched (:id is 123)
/abc/article_xyz no matched
Optional parameters
If the parameter can be not found in pattern when matching url, use ? to declare this situation. ? support named and regexp parameters.
Pattern: /abc/xyz/?:id
/abc/xyz/ matched (:id is empty)
/abc/xyz/123 matched (:id is 123)
Pattern: /abc/xyz/?:id:int
/abc/xyz/ matched (:id is empty)
/abc/xyz/123 matched (:id is 123)
/abc/xyz/aaa no matched
Complex patterns
The fixed segements, named parameters and regexp patterns can be used in one rule together.
Pattern: /article/:id/comment_:page:int
/article/12/comment_2 matched (:id is 12, :page is 2)
/article/abc/comment_3 matched (:id is abc, :page is 3)
/article/abc/comment_xyz no match
Pattern: /data/:year/*/list
/data/2012/11/12/list matched (:year is 2012, :splat is 11/12)
/data/2014/12/list matched (:year is 2014, :splat is 12)
Pattern: /pic/:width:int/:height:int/*.*
/pic/20/20/aaaaaa.jpg matched (:width is 20, :height is 20, :path is aaaaaa, :ext is jpg)
URL : /abc/99
pattern: /abc/99 matched
pattern: /abc/:id no match
pattern: /abc/:id:int no match
URL : /abc/123
pattern: /abc/99 no match
pattern: /abc/:id matched (:id is 123)
pattern: /abc/:id:int no match
If register confusing patterns, it matches first one in adding order. For example, in regexp patterns:
mx := mux.New()
mx.Get("/abc/?:id:int", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "abc, int params %v", mux.Params(r))
})
mx.Get("/abc/?:name:string", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "abc, string params %v", mux.Params(r))
})
mx.Get("/xyz/?:name:string", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "xyz, string params %v", mux.Params(r))
})
mx.Get("/xyz/?:id:int", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "xyz, int params %v", mux.Params(r))
})
When using this mx to match urls, it shows result:
beego/mux có 483 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/beego/mux. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
beego/mux có những chủ đề gì?
GitHub topics của beego/mux: "beego", "golang", "mux", "router". TopGit xếp repo vào nhóm Backend.
beego/mux còn đang phát triển không?
Commit gần nhất trên beego/mux là 9.3 năm trước (theo timestamp GitHub). Repo có 21 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
beego/mux viết bằng ngôn ngữ gì?
beego/mux chủ yếu viết bằng Go. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Cùng nhóm Backend còn repo nào?
beego/mux thuộc nhóm Backend trên TopGit, cùng 4 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về beego/mux ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/beego/mux là nguồn chính thức.
Vì sao beego/mux được xếp vào nhóm Backend?
TopGit xếp beego/mux vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "beego", "golang", "mux"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc mux có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về mux.