• #5 楼 @yedingding 那前台怎么显示后台的内容的?而且不是一次性显示的,肯定是要不断传过来?

  • #3 楼 @huacnlee 不晓得怎么搞的。。没看到 websocket 什么的

  • #26 楼 @luikore Go 里面不会用这种通用类型啊,这样写程序太多转换,不爽了,直接声明 Struct,然后把值,直接就搞到 Struct 里面了,如:

    import (
       "labix.org/v2/mgo"
       v1mgo "labix.org/v1/mgo"
    )
    
    
    type Person struct {
        Name string
        Age int
    }
    
    func main(){
        session, err := mgo.Dial(url)
        var result Person
        c := session.DB(database).C(collection)
        err := c.Find(query).One(&result)
    
        sessionv1, err := v1mgo.Dial(url)
        var resultv1 Person
        c := sessionv1.DB(database).C(collection)
        err := c.Find(query).One(&resultv1)
    
    }
    

    上面的例子,如果 v1 找出来的数据的 Name 不存在,你自然知道是 v1 的问题啊。

  • 就是说,在你的程序里通过 B 的方法返回的 []byte,你就应该知道他是旧驱动的格式,如果你 A 直接调用新驱动的方法返回 []byte,你自然会用新的格式去解析这个 []byte.

    把你的问题的“旧驱动”可以替换成“mongo 驱动”,“新驱动”可以替换成“redis 驱动”,本就是 2 个东西,你就不会搞错了吧。

  • #23 楼 @luikore 但是你用的包就明确了他自己使用哪个版本的啊,你搞清楚你用的那个包使用了哪个版本,就知道他的 byte[] 是按照哪个版本去解析了。

  • 或者这么说吧,你在用 Go 导入包的时候

    package main
    
    import (
       "labix.org/v2/mgo"
       v1mgo "labix.org/v1/mgo"
    )
    
    func main() {
    
        var rv2 mgo.SomeResult
        var rv1 v1mgo.SomeResult
    
        rv2 = rv1 # 这样是付不了值的。
    }
    
  • #20 楼 @luikore 这种情况编译错误,虽然驱动的结果 Struct 名字一样,但是它在不同的包内,是不同的类型,所以付值不会成功的。如果用 Ruby 写的话,你就把 Go 的包理解成这样好了:

    V1 版本:

    module Sinatra
      module V1
        class Something
    
        end
      end
    end
    

    V2 版本:

    module Sinatra
      module V2
        class Something
    
        end
      end
    end
    

    用户用的时候,可以用 Sinatra::V1 也可以用 Sinatra::V2,也可以一起用,本来就是 2 个东西,所以不会冲突或者挂掉。

  • #20 楼 @Saito 我来凑热闹,哈哈,挺@yedingding 讲 Rails 4,其实 Rails 4 是用 Go 重写了。。。

  • #18 楼 @Saito 那不属于踢馆范畴吗?!。。。

  • 可以一直存在 2 份啊,这种情况挺常见的,比如你用到的包就是不更新,依赖 A 包的旧版本,但是提供了你需要的必要功能,而你系统就是要 A 包新版本的功能,这样就让他共存着吧。说到底,A 包的旧版和新版实质是 2 个包。

    Ruby 里面,包名到处写在代码里面。想改成另外一个包的话,要所有代码替换。但是 Go 里面,代码都不要改,就直接发布到另外一个地址上就可以了,比如 labix.org/v2/mgo 和 labix.org/v1/mgo 实际上就是 2 个包,两份代码,大部分相同,小部分改动过。但是你就是可以一个项目即用 v1 的又用 v2 的。这种自由挺好的。如果我需要增强他的功能,我就 Fork 到 github.com/sunfmin/mgo 这样一个项目里面用 3 个包都没问题。

  • #8 楼 @hooopo 哦,对了,rubygems 的一点不好就是,不同的 gem 的 Namespace 可能是一个,会相互覆盖,如果项目中有的 gem 依赖另外一个 gem 的旧版,有的 gem 依赖新版,这样就出乱子了。但是在 Go 里面,2 个包就只能存在在 2 个 Namespace 里面,即使里面代码大部分相同,小部分更改。使用不会受到影响。

  • 如果你一个包的旧版本,在一个项目里面用,新版在另外一个项目里面用,那么就搞出来 2 个仓库,2 个 import 路径,把一个包变成 2 个包。

  • 对啊,Fork 实质上就是 Vendor Everything 啊,如果没发现问题,或者新的需求,为什么要升级?升级肯定是包不能满足你的需求了,但是你升级,就是把 Upstream 的代码 Merge 到自己的 Fork 里就行了。然后编译,测试。

    依赖不会有冲突啊,两个不同 import 地址的包,就是 2 个包,即使代码一模一样。

  • #6 楼 @ashchan 赶紧的

  • 我也来凑热闹。

  • 记得曾经写过邮件来说服领导,就不翻译了

    For my self, I like Go much that I won't like to write program in any another language any more, haha.

    A few points of mine:

    • Go is compiled, the static check is really helpful for trivial bugs, For for large team development, I can't imagine you can work on a ruby project that with 50 more developers. and I imagine our company will be doing big projects eventually.

    • Go embed synchronized function calls (aka goroutines and channels) are really really good features that otherwise you will require a background job queue to do simliar kind of thing but difficult be synchronized back when you need them

    • Go is fast enough, I am not saying Ruby is slow, of course you can write fast Ruby programs, But the matter is how hard it is to write fast programs. For a normal developer, that you don't need special training for performance tips, you just write your code in Go, and it's fast enough, The bottle neck is rarely in Go.

    • Go is simple, Not so much concept about like Mixed in, Meta Programming, Sub Class inherence, Method Overriding, etc, It's just packages, funcs, funcs on struct, structs, package variables. For a new developer, I think it's much easier to learn than any other language.

    • Go has the best standard package documentations than any other language I know and The most simple and useful standard packages, it's not bloated, but really really useful and can do a lots of things. you just give it a check at http://golang.org/pkg, Until now I still not sure what's the difference between Ruby Core and Ruby Standard Library

    • Go is so easy to deploy, clone the code on server, run go install and ruby the generated binary command. If you compiled alright on the server, It basically no further problems, and If you compiled wrong, It won't effect the old running binary command.

    • A lots of concurrency stuff could be easily implemented in Go, please give it a check at: http://concur.rspace.googlecode.com/hg/talk/concur.html#landing-slide

    • A few people I think is really smart are behind Go:

      • Ken Thomason, Rob Pike, etc those all big guys in IT world no need to explain, :-)
      • Brad Fitzpatrick: The memcached author, Now mainly develop the Go language in Google, and He said he is using Go exclusively now: https://gist.github.com/2396390
      • Russ Cox: Not sure what big thing he do, But I think He is smart.
    • People outside of Google interesting in Go:

    • Companies using Go: http://go-lang.cat-v.org/organizations-using-go

    Yes, We are new to Go, and Go is new, fewer packages, fewer developers. But I believe it will blossom as time goes. And as our company accumulate more and more Go power, We can do any big project with high quality and good performance, and no mid-night calls for server down, :)

    It's just my few points, :-)

  • 我的个人经验就是,用 Java 的时候,各种架构太复杂,IoC,EJB 各种,之前做 Java 时候从来没自己成功上线过一个项目,因为部署也不简单。当 Rails 出现的时候,感觉看到了曙光,15 分钟就上线 Blog,太快了。写起来太舒服了。

    但是后来,项目越写越大,动态脚本语言的缺陷就暴漏出来了,依赖编译都能排除的 Bug,只能通过多写测试来确保了,测试越写越多,越运行越慢,小团队可以,但是有谁见过比如 50 人做一个 Rails 项目,当然能做,但是肯定会花费更多额外的精力。

    那 Go 就是编译,并发模型支持,写起来也不像 Java 那么繁琐,但相对 Ruby 还是要繁琐点,性能比 Ruby 强,就是写的时候,只管写代码,实现了,性能基本过得去,但 Ruby 和 Rails 都不一样了。

    另外虽然我觉得 Ruby 的 gems 挺好,但是我个人觉得 Go 的包管理更好,稳定的包直接就用,不稳定的 Fork 到自己的 Github 上,进行 hack,然后直接引用自己的包,当然 Ruby 也能这种方式,但是发布 Gem,还是比较有一定的台阶的,不是 Fork 下来就能用这种。

    安装依赖,也不用去维护个 gemfile,因为依赖都在代码里,编译器保证了你的依赖在你的代码里调用过的,引用了没调用过的包,你编译都通不过。

  • 这个必须顶顶!

  • 成果物

    https://gist.github.com/4239211

    package main
    
    import (
        "code.google.com/p/go.net/websocket"
        // "io"
        "log"
        "net/http"
    )
    
    type Room struct {
        Id      string
        Sockets []*websocket.Conn
    }
    
    var Rooms = []Room{}
    
    func MyRoom(id string, ws *websocket.Conn) (r Room) {
    
        for _, room := range Rooms {
            if room.Id == id {
                r = room
                break
            }
        }
    
        r.Id = id
        r.Sockets = append(r.Sockets, ws)
        Rooms = append(Rooms, r)
        return
    }
    
    func (r Room) BroadCast(message string) (err error) {
        for _, ws := range r.Sockets {
            websocket.Message.Send(ws, message)
        }
        return
    }
    
    // hello world, the web server
    func Connect(ws *websocket.Conn) {
        log.Println("IN", ws.Request().URL.Query())
        room := MyRoom(ws.Request().FormValue("url"), ws)
        log.Println(Rooms[0], Rooms)
        for {
            var message string
            err := websocket.Message.Receive(ws, &message)
            if err != nil {
                log.Println(err)
                return
            }
            log.Println(message)
            room.BroadCast(message)
        }
    }
    
    func main() {
        http.Handle("/connect", websocket.Handler(Connect))
        err := http.ListenAndServe(":12345", nil)
        if err != nil {
            log.Fatal("ListenAndServe: ", err)
        }
    }
    
    
  • #35 楼 @bhuztez 这么明显啊。。

  • #33 楼 @bhuztez 你来不来啊?!

  • 没人感兴趣的样子。

  • #21 楼 @yedingding 请准备,哈哈。一起去买也行,旁边有便利店。

  • #15 楼 @luikore 必须来啊!

  • #17 楼 @yedingding 没优惠。。。我们就码农啊,有什么优惠。

  • #13 楼 @bhuztez 你来做 Ejabberd 版的啊。

  • #11 楼 @bhuztez YES, 中国官网

  • 顺便发下公司刚刚上线的中国 ASICS 新网站 http://www.asics.com.cn/

  • #7 楼 @yakczh 2 个 tab 连过来,当成一个用户啊,可以做成 2 个 tab 都发消息,也可以做成,那个 Active,就发哪个。