brady-wang

github地址

https://gitee.com/mirrors/mux#examples

参考代码

package main

import (
	"fmt"
	"net/http"
	"github.com/gorilla/mux"
)

func main() {

	// IMPORTANT: you must specify an OPTIONS method matcher for the middleware to set CORS headers
	r := mux.NewRouter()
	r.HandleFunc("/articles/{category}/", ArticlesCategoryHandler)
	http.Handle("/", r)

	http.ListenAndServe(":8080", r)
}

func ArticlesCategoryHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, "Category: %v\n", vars["category"])
}

go run main.php
浏览器访问 http://localhost:8080/articles/werwer/

这个包只是路由分发,http访问还是要自带的http

分类:

技术点:

相关文章:

  • 2021-12-01
  • 2021-05-26
  • 2021-08-07
  • 2021-08-18
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
猜你喜欢
  • 2021-08-17
  • 2021-07-31
  • 2022-12-23
  • 2022-02-07
  • 2021-12-05
  • 2023-01-30
  • 2021-05-13
相关资源
相似解决方案