golang的框架只是在net/http上加上了 get/post 分类,把http.ResponseWriter, http.Request合并成一个
常用的操作封装到String/HTML/JSON 如果需要用不常用的方法,还是要调用Write/Request / Header() 该写的hundlefunc一行都少不了
如果使用框架中有些细节与预期不符,给作者提issue 你认为是bug,作者认为这是feature 比如
参考 net/http
`/hello/name/` 是不匹配 /hello/name 这样的路由的
```
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/hello/name", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
http.ListenAndServe(":8080", nil)
}
```
$curl http://localhost:8080/hello/name/
Not found
但是很多框架 要么是算成匹配成功,反回200,有的是301,有的302 提issue 回复这是feature,不服来战,然后就卡壳了
![bufulaizhan.jpg](https://static.studygolang.com/210906/67c9f3d0b5764f2d94843aa2bb7d0b54.jpg)
更多评论
1楼 <a href="/user/focusonline" title="@focusonline">@focusonline</a> 8080是另外一个框架的端口,完整的代码
```
package main
import "github.com/yarf-framework/yarf"
type Hello struct {
yarf.Resource
}
func (h *Hello) Get(c *yarf.Context) error {
c.Render("Hello, " + c.Param("name"))
return nil
}
func main() {
y := yarf.New()
hello := new(Hello)
y.Add("/hello/:name", hello)
y.Start(":8080")
}
```
$ http://localhost:8080/hello/world/
#2