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

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
浏览: 1218 次
点击打开新窗口浏览全图

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

 

Tags: go

对着谢大的教程写代码(一)

 谢大的教程在:https://github.com/astaxie/build-web-application-with-golang

在复刻和学习的过程中,把问题记录下来的笔记
 
1、
XML/HTML代码
  1. // 声明一个数组  
  2. var array = [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}  
  3. // 声明两个slice  
  4. var aSlice, bSlice []byte  
  5.   
  6. // 演示一些简便操作  
  7. aSlice = array[:3] // 等价于aSlice = array[0:3] aSlice包含元素: a,b,c  
  8. aSlice = array[5:] // 等价于aSlice = array[5:10] aSlice包含元素: f,g,h,i,j  
  9. aSlice = array[:]  // 等价于aSlice = array[0:10] 这样aSlice包含了全部的元素  
  10.   
  11. // 从slice中获取slice  
  12. aSlice = array[3:7]  // aSlice包含元素: d,e,f,g,len=4cap=7  
  13. bSlice = aSlice[1:3] // bSlice 包含aSlice[1], aSlice[2] 也就是含有: e,f  
  14. bSlice = aSlice[:3]  // bSlice 包含 aSlice[0], aSlice[1], aSlice[2] 也就是含有: d,e,f  
  15. bSlice = aSlice[0:5] // 对slice的slice可以在cap范围内扩展,此时bSlice包含:d,e,f,g,h  
  16. bSlice = aSlice[:]   // bSlice包含所有aSlice的元素: d,e,f,g  
主要是加深颜色的那句。。。。
2、
go代码
  1. type human struct {  
  2.     name   string  
  3.     age    string  
  4.     height int  
  5. }  
  6. type student struct {  
  7.     human  
  8.     skills  
  9.     int  
  10.     age        int  
  11.     speciality string  
  12. }  
  13. func (h *human) sayhi() {  
  14.     fmt.Printf("human say hello, i'm %s \n", h.name)  
  15. }  
  16. func (h *human) gogo() {  
  17.     fmt.Println("gogogo");  
  18. }     
  19. type men interface{  
  20.     sayhi()  
  21.     gogo()  
  22. }  
  23.   
  24. 然后用的地方:  
  25.     mike := student{human:human{name:"mike"}}  
  26.     var i men;  
  27.     i = mike;  
  28.     i.sayhi();  
因为这是早期的所见所得编辑器。对于代码高亮做的不好。忍忍吧。。。
上面的代码是会出错的。
cannot use mike (type student) as type men in assignment:
student does not implement men (gogo method requires pointer receiver)
需要:mike := &student{human:human{name:"mike"}}
看到没,在student前有个取址符。主要是因为方法指定的是:(h *human),如果是(h human),就不需要取址符了
*human 是指针,但是你mike不是指针,只是对象,所以没有实现这两个方法,才会报错
然后谢大给出了这个:http://segmentfault.com/q/1010000000198984#a-1020000000199002,说是里面有解释
XML/HTML代码
  1. 假设T是struct,那么Go里面遵循下面几个原则:  
  2.   
  3.    T的方法集仅拥有 T Receiver 方法。  
  4.    *T 方法集则包含全部方法 (T + *T)。  

  5. 所以你上面的例子dept1应该是拥有方法:Name和SetName    
  6. 而&dept1拥有方法:Name、SetName和Relocate  
  7. 这个就是Go里面在设计方法的时候需要注意Receiver的类型  

Tags: go, astaxie

GO 的一个小陷阱

在群里突然看到一段代码:

XML/HTML代码
  1. package main  
  2.   
  3. import (  
  4.     "fmt"  
  5. )  
  6.   
  7. var DomainId int  
  8.   
  9. func init() {  
  10.     DomainId, err :GetDomainId()  
  11.     if err != nil {  
  12.         DomainId = -1  
  13.     }  
  14.     fmt.Println(DomainId)  
  15. }  
  16.   
  17. func GetDomainId() (int, error) {  
  18.     DomainId = 1  
  19.     return DomainId, nil  
  20. }  

注意看红色背景的一条,理论上这段代码没有错,但事实上会报错了。

XML/HTML代码
  1. [上海]Asta谢()  22:29:50  
  2. 我知道  
  3. [上海]Asta谢()  22:29:55  
  4. 我踩过这个坑  
  5. [上海]Asta谢()  22:30:04  
  6. init里面不能用:=  

所以,上面的代码应该是写成:

XML/HTML代码
  1. func init() {  
  2.     var err error  
  3.     DomainId, err = GetDomainId()  
  4.     if err != nil {  
  5.         DomainId=-1  
  6.     }  
  7. }  

对比两段红色背景的代码。主要是做个笔记 .怕会忘 .

Asta谢 是谁?看这里:https://github.com/astaxie/build-web-application-with-golang ,这里有一篇他的教程,适合广大人民群众查看

Tags: go