Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
忍不住对net.http吐下槽
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Changming Sun  
View profile   Translate to Translated (View Original)
 More options May 13 2012, 6:52 am
From: "Changming Sun" <m...@sunchangming.com>
Date: Sun, 13 May 2012 18:52:26 +0800
Local: Sun, May 13 2012 6:52 am
Subject: 忍不住对net.http吐下槽

ServeMux这个类中有一个map,存储从url pattern到Handler的映射。

这些代码不知道是谁写的,感觉就像玩具一样。

这里的pathMatch,既不是精确匹配,也不是正则匹配,而是按前缀匹配。

match函数在对ServeMux里这个map做查找的时候,是全遍历,然后取长度最长的。通常来说,我们写的pattern都是精确的url,但是这里的匹 配方式,使得即使找到了我想要的那个handler,还是得继续continue到最后一个record。

另外,我无法往这里面注册”/”。

因为我一旦注册了”/”,所有的url都会被匹配,那么无论来什么请求,都不会返回404。

  smime.p7s
8K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ruiqi Hong  
View profile   Translate to Translated (View Original)
 More options May 13 2012, 8:06 am
From: Ruiqi Hong <hongru...@gmail.com>
Date: Sun, 13 May 2012 20:06:35 +0800
Local: Sun, May 13 2012 8:06 am
Subject: Re: [gocn:3949] 忍不住对net.http吐下槽

在 2012年5月13日 下午6:52,Changming Sun <m...@sunchangming.com>写道:

> ServeMux这个类中有一个map,存储从url pattern到Handler的映射。****

> 这些代码不知道是谁写的,感觉就像玩具一样。****

> 这里的pathMatch,既不是精确匹配,也不是正则匹配,而是按前缀匹配。****

> match函数在对ServeMux里这个map做查找的时候,是全遍历,然后取长度最长的。通常来说,我们写的pattern都是精确的url
> ,但是这里的匹配方式,使得即使找到了我想要的那个handler,还是得继续continue到最后一个record。****

> 另外,我无法往这里面注册”/”。****

> 因为我一旦注册了”/”,所有的url都会被匹配,那么无论来什么请求,都不会返回404。****

通常来说,我们写的pattern都是精确的url
这点有疑问,没有正则的情况下,很多url
pattern确实只是前缀,最长匹配可以适应更多情况。而且不用考虑pattern注册的顺序,意味着pattern可以在不同的地方注册而不用集中管理。如 果用正则就是另外一回事了。
404的问题:Python中通常也会有一个/.*,也会造成这个问题吧...在handler逻辑里处理下就好了
个人觉得只是使用习惯问题...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
shiwei xu  
View profile   Translate to Translated (View Original)
 More options May 13 2012, 9:48 pm
From: shiwei xu <xushiwe...@gmail.com>
Date: Mon, 14 May 2012 09:48:11 +0800
Local: Sun, May 13 2012 9:48 pm
Subject: Re: [gocn:3949] 忍不住对net.http吐下槽

我觉得不玩具。原因:

1. go 的 http 不希望引入 regex 来做路由表。
2. go 的路由要想优化比 regex
方式空间大,比如用编译原理中处理正则匹配的状态机来compile下路由表,完全可以做到只遍历一遍url就完成,这会比其他框架的路由表高效很多。
只是没急着在这里去优化,因为遍历看起来慢,但通常一个 server 的路由比较少,其实最多也就几十个而已。

在 2012年5月13日 下午6:52,Changming Sun <m...@sunchangming.com>写道:

> ServeMux这个类中有一个map,存储从url pattern到Handler的映射。****

> 这些代码不知道是谁写的,感觉就像玩具一样。****

> 这里的pathMatch,既不是精确匹配,也不是正则匹配,而是按前缀匹配。****

> match函数在对ServeMux里这个map做查找的时候,是全遍历,然后取长度最长的。通常来说,我们写的pattern都是精确的url
> ,但是这里的匹配方式,使得即使找到了我想要的那个handler,还是得继续continue到最后一个record。****

> 另外,我无法往这里面注册”/”。****

> 因为我一旦注册了”/”,所有的url都会被匹配,那么无论来什么请求,都不会返回404。****

--
许式伟
https://qbox.me

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Changming Sun  
View profile   Translate to Translated (View Original)
 More options May 13 2012, 10:57 pm
From: "Changming Sun" <m...@sunchangming.com>
Date: Mon, 14 May 2012 10:57:43 +0800
Local: Sun, May 13 2012 10:57 pm
Subject: RE: [gocn:3955] 忍不住对net.http吐下槽

Ψ  go 的路由要想优化比 regex 方式空间大

从理论上来说,需求越简单,实现就可以越高效。当它实际想去做那些优化的时候,代码就没现在这么优雅了。

而且,go 1已经发布了,接口不适合再做大的变动。按现在的接口规范来说,没法注册”/”。


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ruiqi Hong  
View profile   Translate to Translated (View Original)
 More options May 14 2012, 2:40 am
From: Ruiqi Hong <hongru...@gmail.com>
Date: Mon, 14 May 2012 14:40:18 +0800
Local: Mon, May 14 2012 2:40 am
Subject: Re: [gocn:3956] 忍不住对net.http吐下槽

注册 /,然后在 / 的handler里,判断路径。如果不是 / ,返回 404 不行么?

在 2012年5月14日 上午10:57,Changming Sun <m...@sunchangming.com>写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Liigo Zhuang  
View profile   Translate to Translated (View Original)
 More options May 14 2012, 9:00 pm
From: Liigo Zhuang <com.li...@gmail.com>
Date: Tue, 15 May 2012 09:00:41 +0800
Local: Mon, May 14 2012 9:00 pm
Subject: Re: [gocn:3957] 忍不住对net.http吐下槽

我也不觉得是玩具,没有这么丑陋的玩具。我想做成精确匹配和模糊匹配相结合比较好,是否模糊匹配应该取决于用户的pattern,如 /* 应模糊匹配, /
应精确匹配,这样程序员有明确的预期。从现在的结果看,它的设计思路和出发点有问题,给用户/程序员造成了不必要的困扰,额外引入了复杂度。但是这里的fans 们是不会正视问题的。

--
by *Liigo*, http://blog.csdn.net/liigo/
Google+  https://plus.google.com/105597640837742873343/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xing Xing  
View profile   Translate to Translated (View Original)
 More options May 14 2012, 9:23 pm
From: Xing Xing <mikesp...@gmail.com>
Date: Tue, 15 May 2012 09:23:22 +0800
Local: Mon, May 14 2012 9:23 pm
Subject: Re: [gocn:3965] 忍不住对net.http吐下槽
于 Tue, 15 May 2012 09:00:41 +0800
Liigo Zhuang <com.li...@gmail.com> 写道:

> 我也不觉得是玩具,没有这么丑陋的玩具。我想做成精确匹配和模糊匹配相结合比较好,是否模糊匹配应该取决于用户的pattern,如 /*
> 应模糊匹配, /
> 应精确匹配,这样程序员有明确的预期。从现在的结果看,它的设计思路和出发点有问题,给用户/
> 程序员造成了不必要的困扰,额外引入了复杂度。但是这里的fans们是不会正视问题的。

引用 rsc 的话说“Sorry, but no.”。

golang 的思想更接近 c,而不是 java 或者 dotnet。

实际上在现有相对成熟的 web 框架中,router
往往都是作为一个独立的模块存在的。那么我认为 golang 也不会例外,现有的
net/http 包已经提供了足够的完整的 http 所需的功能。至于 session、router
这其实与 http 本身并无关系,只是需要 session、router 与 http
配合实现更加高效的开发。

一句话,不要期望基础库承载所有开发需求。

如果你有更好的设计,完全可以开发一个 router 的  package:

r := router.New()
// r := router.NewFromServerMux(sm *http.ServerMux)
r.Regex("/[a-z]+/[0-9]+", fooHandler)
r.Wildcard("/*", fooHandler)
r.NotFound(notFoundHandler)
r.InternalError(internalErrorHandler)

另外,Liigo,讨论就是讨论,咱们不提什么 fans 不
fans,正视不正视的这些容易引起毫无意义的口水仗的内容好不?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Changming Sun  
View profile   Translate to Translated (View Original)
 More options May 14 2012, 10:45 pm
From: "Changming Sun" <m...@sunchangming.com>
Date: Tue, 15 May 2012 10:45:45 +0800
Local: Mon, May 14 2012 10:45 pm
Subject: RE: [gocn:3957] 忍不住对net.http吐下槽

我一旦注册了”/”,所有的url都会被匹配,那么无论来什么请求,都不会返回404。

From: golang-china@googlegroups.com [mailto:golang-china@googlegroups.com] On Behalf Of Ruiqi Hong
Sent: 2012年5月14日 14:40
To: golang-china@googlegroups.com
Subject: Re: [gocn:3957] 忍不住对net.http吐下槽

注册 /,然后在 / 的handler里,判断路径。如果不是 / ,返回 404 不行么?

  smime.p7s
8K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
qq wu  
View profile   Translate to Translated (View Original)
 More options May 14 2012, 11:19 pm
From: qq wu <wuqq...@gmail.com>
Date: Tue, 15 May 2012 11:19:42 +0800
Local: Mon, May 14 2012 11:19 pm
Subject: Re: [gocn:3967] 忍不住对net.http吐下槽

既然你注册了 ”/” ,在相应的 handler 中检查一下 url ,对于错误情况返回 404 就可以了。这个很简单啊。
我也同意 Xing Xing 的看法,url 的 dispatch 已经和 http 协议本身没有多大关系了,应该再另起一个包。模块的分工应该更明确。

在 2012年5月15日 上午10:45,Changming Sun <m...@sunchangming.com>写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ruiqi Hong  
View profile   Translate to Translated (View Original)
 More options May 14 2012, 11:52 pm
From: Ruiqi Hong <hongru...@gmail.com>
Date: Tue, 15 May 2012 11:52:19 +0800
Local: Mon, May 14 2012 11:52 pm
Subject: Re: [gocn:3969] 忍不住对net.http吐下槽

我只是提供一个在当前环境下的解决方案,并不是说可以这样就很好。
一开始用 HTTP
包的时候,我也觉得路径选择为什么没有用Python很多框架那样的正则,而是用了这样奇怪的方式。可以用多了以后,发现功能也没有想象中的那么弱,只是很多需 求需要自己去实现(很多其它的Package也是这样的)。如果路径选择中出现路径匹配不了的状况,那是不是还要专门提供一个接口定义错误页面?
至于前缀匹配即可匹配整个URL和“/”的问题,我觉得是文档没有说清楚(文档没有说清楚的地方也有很多)。要是文档明确也就没有什么困扰了。


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
qihang zhang  
View profile   Translate to Translated (View Original)
 More options Jul 9 2012, 3:47 am
From: qihang zhang <qihan...@gmail.com>
Date: Mon, 9 Jul 2012 15:47:25 +0800
Local: Mon, Jul 9 2012 3:47 am
Subject: Re: [gocn:3970] 忍不住对net.http吐下槽

可以看一下这个

http://go.pkgdoc.org/code.google.com/p/gorilla

项目。

挺全的工具包

其中
mux <http://go.pkgdoc.org/code.google.com/p/gorilla/mux>Package gorilla/mux
implements a request router and
dispatcher.pat<http://go.pkgdoc.org/code.google.com/p/gorilla/pat>Package
gorilla/pat is a request router and dispatcher with a pat-like interface.

这两个是用来dispatcher的

在 2012年5月15日 上午11:52,Ruiqi Hong <hongru...@gmail.com>写道:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
高帆  
View profile   Translate to Translated (View Original)
 More options Sep 3 2012, 3:37 am
From: 高帆 <rias...@gmail.com>
Date: Mon, 3 Sep 2012 15:37:24 +0800
Local: Mon, Sep 3 2012 3:37 am
Subject: Re: [gocn:4602] 忍不住对net.http吐下槽

我也同意基础部分不要用正则,正则相对于专门为URL写的状态机机制还是慢很多的。

在 2012年7月9日 下午3:47,qihang zhang <qihan...@gmail.com>写道:

--
welcom to http//www.fanflash.cn

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »