1. 首页
  2. 主题
  3. Go Web开发

用了golang框架是否降低了开发效率

tablecell · · 2597 次点击
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)
3楼 <a href="/user/focusonline" title="@focusonline">@focusonline</a> 定的路由是 ` /hello/:name ` 期望 - $curl http://localhost:8080/hello/jack 返回200 - $curl http://localhost:8080/hello/jack/ 返回404 net/http 也是这样处理的 但是很多框架封装了net/http以后就不一样了 - $curl http://localhost:8080/hello/jack 返回200 - $curl http://localhost:8080/hello/jack/ 有的是返回200 有的返回301 有的返回302
#4
更多评论
看不懂楼主在说什么... 例子的代码和测试完全不符合, 一个监听80端口, 一个访问8080...
#1
1楼 <a href="/user/focusonline" title="@focusonline">@focusonline</a> 8080是另外一个框架的端口,完整的代码 ``` package main import &#34;github.com/yarf-framework/yarf&#34; type Hello struct { yarf.Resource } func (h *Hello) Get(c *yarf.Context) error { c.Render(&#34;Hello, &#34; + c.Param(&#34;name&#34;)) return nil } func main() { y := yarf.New() hello := new(Hello) y.Add(&#34;/hello/:name&#34;, hello) y.Start(&#34;:8080&#34;) } ``` $ http://localhost:8080/hello/world/
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中