在Golang裡,原生的 net/http 函式庫中,用來創造路由的方法
使用原生的方式產生路由
package main
import (
	"fmt"
	"net/http"
)
func index(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Welcome!\n")
}
func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", index)
	server := &http.Server{
		Addr:    "127.0.0.1:9921",
		Handler: mux,
	}
	server.ListenAndServe()
}
FastHttpRouter 是一個高效能且輕量的路由框架,擴展性高
使用框架 FastHttpRouter 產生路由
package main
import (
	"fmt"
	"log"
	"github.com/buaazp/fasthttprouter"
	"github.com/valyala/fasthttp"
)
func Index(ctx *fasthttp.RequestCtx) {
	fmt.Fprint(ctx, "Welcome!\n")
}
func main() {
	router := fasthttprouter.New()
	router.GET("/", Index)
	log.Fatal(fasthttp.ListenAndServe(":8080", router.Handler))
}
Which is the fastest web framework?  在這項實驗中紀錄了 FastHttpRouter 在各框架中排名蠻前面的,在這種 Side Project 很值得一試。
重要的是,再經過重複造輪子時期之後,希望減少開發時間,不再重複製造輪子,於是使用框架在產品中。
於是,利用 FastHttpRouter 作為 GamiLMS 的路由框架。