手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2025年07月的文章

using NGINX or not?

 有人在stackoverflow上面提问:

http://stackoverflow.com/questions/17776584/webserver-for-go-golang-webservices-using-nginx-or-not
  1. I am writing some webservices returning JSON data, which have lots of users.    
  2. Would you recommend to use NGINX as a webserver or it is good enough to use the standard http server of Go?  

于是有人就回答了:

XML/HTML代码
  1. It depends.  
  2.   
  3. Out of the box, putting nginx in front as a reverse proxy is going to give you:  
  4.   
  5. Access logs  
  6. Error logs  
  7. Easy SSL termination  
  8. SPDY support  
  9. gzip support  
  10. Easy ways to set HTTP headers for certain routes in a couple of lines  
  11. Very fast static asset serving (if you're serving off S3/etc. though, this isn't that relevant)  
  12. The Go HTTP server is very good, but you will need to reinvent the wheel to do some of these things (which is fine: it's not meant to be everything to everyone).  
  13.   
  14. I've always found it easier to put nginx in front—which is what it is good at—and let it do the "web server" stuff. My Go application does the application stuff, and only the bare minimum of headers/etc. that it needs to. Don't look at putting nginx in front as a "bad" thing.  

还有人回答:

XML/HTML代码
  1. The standard http server of Go is fine. If your application mostly/only are "dynamic" requests/responses, then it's really the best way.  
  2.   
  3. You could use nginx to serve static assets, but most likely the standard Go one is fine for that, too. If you need higher performance you should just use a CDN or cache as much as you can with Varnish (for example).  
  4.   
  5. If you need to serve different applications off the same IP address, nginx is a fine choice for a proxy to distribute requests between the different applications; though I'd more often get Varnish or HAProxy out of the toolbox for that sort of thing.  

这回你觉得呢?你还会用nginx吗?还是只用go做http server/???

Tags: nginx, go

上海首届GO聚会开始了

 不要犹豫了,上海首届golang聚会就这样悄悄的开始了。Think2Go戈登营(Think技术社区Go语言Camp)首期,再晚你就可能没有机会参加首届聚会了,这次只有30个人,是在一个小小的咖啡馆里举行的。

话题主要由3位达人进行分享:

《开场》 Think社区

Go语言在CDN下载系统中的应用谢孟军 盛大云 高级研究员

Go在微博数据分析中的应用邵天宇 Buzzreader 高级工程师 

golang与高强度在线服务韩拓,七牛云 CTO

《OpenTalk》所有参与者  

 

是不是觉得很心动?参加地点其实也不算远(对上海的朋友来说),地方很好找。点评网上也有介绍:http://www.dianping.com/shop/6630958,直接点过去看看就OK了。详细地址在:上海市卢湾区蒙自东路63号(近马当路地铁站3号口)

费用不算太高,98元,应该是都能够承受的价格了。毕竟占用了咖啡店30个座位,别人也要做生意的。。。

大小: 41.19 K
尺寸: 500 x 228
浏览: 1468 次
点击打开新窗口浏览全图

上传一张成功的订座票。处女票,值得收藏。。。可惜没有实体的

 

Tags: go

时隔N久,不再使用量子统计了

 量子统计应该算是我用的时间最长的一个统计程序了吧?看看量子统计上是怎么写的:

XML/HTML代码
  1. 名称:飞天小肥猪的简单人生  
  2. 地址:http://neatstudio.com  
  3. 类型:电脑科技  
  4. 开始统计时间:2008-06-25  
  5. 已统计时间:1897天  

之所以不用它。一来它的统计其实并没有那么的精确,二来也经常被人挂马,三来,这么多年来几乎是不思进取。四来,用了腾讯的统计后,发现速度、效果等都远超它了。

于是,今天正式停用量子统计,转用腾讯的统计程序。

 

 

go获取当前的公网IP

 获取公网IP的方法其实很简单,最简单的就是利用dnspod的服务,echo `nc ns1.dnspod.net 6666`,立刻就出来了。于是hugozhu的一段代码就是这样写的:

XML/HTML代码
  1. func GetLocalPublicIpUseDnspod() (string, error) {  
  2.     timeout :time.Nanosecond * 30  
  3.     conn, err :net.DialTimeout("tcp", "ns1.dnspod.net:6666", timeout*time.Second)  
  4.     defer func() {  
  5.         if x :recover(); x != nil {  
  6.             log.Println("Can't get public ip", x)  
  7.         }  
  8.         if conn != nil {  
  9.             conn.Close()  
  10.         }  
  11.     }()  
  12.     if err == nil {  
  13.         var bytes []byte  
  14.         deadline :time.Now().Add(timeout * time.Second)  
  15.         err = conn.SetDeadline(deadline)  
  16.         if err != nil {  
  17.             return "", err  
  18.         }  
  19.         bytes, err = ioutil.ReadAll(conn)  
  20.         if err == nil {  
  21.             return string(bytes), nil  
  22.         }  
  23.     }  
  24.     return "", err  
  25. }  

上面的原始代码在:http://hugozhu.myalert.info/2013/02/26/dynamic-dns-script.html,原文的代码中其实是不能运行的。因为:timeout是个未定义的变量。

OK,不说这个。我在现实中不能使用上面的代码,因为nc ns1.dnspod.net取出来的结果不正确。为什么?因为我用的是铁通,好象会经过一层代理。但是我访问ip138又是可以取到真实的公网IP,所以我使用了如下代码 :

XML/HTML代码
  1. func GetLocalPublicIp() (string, error) {  
  2.     // `nc ns1.dnspod.cn 6666`  
  3.     res, err :http.Get("http://iframe.ip138.com/ic.asp")  
  4.     if err != nil {  
  5.         return "", err  
  6.     }  
  7.     defer res.Body.Close()  
  8.     result, err :ioutil.ReadAll(res.Body)  
  9.     if err != nil {  
  10.         return "", err  
  11.     }  
  12.     reg :regexp.MustCompile(`\d+\.\d+\.\d+\.\d+`)  
  13.     return reg.FindString(string(result)), nil  
  14. }  

上面我用的正则十分简单。就这样写写算了。因为这个页面里就这么一个符合的地方。OK,现在就一切正常了

wget post数据

 一直以为wget只是下载点东西的工具。看到一篇网上的文章,才注意到wget原来还可以post数据。

为什么我想用wget来post数据呢?是因为。。。busybox不带curl,而bash版的ddns更新(dnspod的域名更新)是使用curl的。既然curl不支持,我就google了一下:wget能够post数据吗?
果然,第一篇就是:
http://hi.baidu.com/hhflying/item/7ae51f3d30ce64fdde2221d9
  1. 这段时间需要用wget做一些事情,主要是抓取网页的数据工作,发现wget还是很强大的。下面是一些应用场景:  
  2. 1. 简单页面的抓取  
  3. wget的最基本用法  
  4. wget http://domain.com/path/simple_page.html  
  5. 2. 添加自己的head  
  6. 有些网站或者页面,需要额外的认证,所以需要添加额外的HTTP Header,使用方法:  
  7. wget --header="MyHeader: head_value" http://domain.com/path/page/need_header.php  
  8. 3. 伪装成浏览器  
  9. 有些网站,例如facebook,会检测请求方式是否是浏览器,如果不是正常的浏览器,那么会redirect到一个"incompatible browser"的错误页面。这时候需要wget伪装成一个浏览器(我是Mozilla Firefox!):  
  10. wget --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)" http://domain.com/path/page/check_user_agent.php  
  11. 4. post数据到某个页面  
  12. wget不光可以用get方式请求网页,还可以post data的,那样就可以实现自动注册、自动登录了(有验证码的页面除外。。。。)  
  13. wget --post-data="user=user1&pass=pass1&submit=Login" http://domain.com/login.php  
  14. 5. 访问需要登录的页面  
  15. 有些页面的访问需要登录,访问的时候需要传递cookie,这时候就需要和上面提到的post方式结合。一般过程是:post用户名和密码登录、保存cookie,然后访问页面时附带上cookie。  
  16. wget --post-data="user=user1&pass=pass1&submit=Login" --save-cookies=cookie.txt --keep-session-cookies http://domain.com/login.php  
  17. wget --load-cookies=cookie.txt http://domain.com/path/page_need_login.php  
  18. 暂时就探索到这些,以后有什么新的用法,继续补充。  
不过,可惜的是,我运行下来之后,还有一个小问题:
https://dnsapi.cn/Record.Ddns: HTTPS support not compiled in.
哎。。。我没有openssl,https不支持啊。。纠结,uis2000的路真难走。
 

Tags: wget, uis2000