Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
go程序抛出错误找不到程序包“;code.google.com/p/go.net/websocket“;_Go - Fatal编程技术网

go程序抛出错误找不到程序包“;code.google.com/p/go.net/websocket“;

go程序抛出错误找不到程序包“;code.google.com/p/go.net/websocket“;,go,Go,我是编程语言新手。下面是我的代码 package main import ( "code.google.com/p/go.net/websocket" "fmt" "net/http" "strconv" ) var add := "12345" func EchoLengthServer(ws *webscoket.Conn) { var msg string for { websocket.Message.Receive

我是编程语言新手。下面是我的代码

package main

import (
    "code.google.com/p/go.net/websocket"
    "fmt"
    "net/http"
    "strconv"
)

var add := "12345"

func EchoLengthServer(ws *webscoket.Conn) {
    var msg string

    for {
        websocket.Message.Receive(ws, &msg)
        fmt.Println("Got Message", msg)
        length := len(msg)
        if err := websocket.Message.Send(ws, strconv.FormatInt(int64(length), 10)); err != nil {
            fmt.Println("can't send message length")
            break
        }
    }
}

func websocketListen() {
    http.Handle("/length", websocket.Handler(EchoLengthServer))
    err := http.ListenAndServe(addr, nil)
    if err != nil {
        panic("ListenAndServe:" + err.Error())
    }
}
当我执行代码时,我发现了下面的错误

[rajkumar@localhost ch4-DesigningAPI]$ go run WebSockets.go 
WebSockets.go:6:3: cannot find package "code.google.com/p/go.net/websocket" in any of:
    /usr/local/go/src/code.google.com/p/go.net/websocket (from $GOROOT)
    /home/rajkumar/GOPackages/src/code.google.com/p/go.net/websocket (from $GOPATH)
我试图通过go get命令在GOPATH中添加websocket包,但这也引发了下面的错误

[rajkumar@localhost ch4-DesigningAPI]$ go get code.google.com/p/go.net/websocket
go: missing Mercurial command. See http://golang.org/s/gogetcmd
package code.google.com/p/go.net/websocket: exec: "hg": executable file not found in $PATH
你能帮我解决这个错误吗。

这个怎么样

$ go get -v golang.org/x/net/websocket
golang.org/x/net/websocket
$
-


只需安装Mercurial。这与围棋无关。@Volker:is
code.google.com/p/go.net/websocket
已过时:。@Peter是的,但导入旧版本(无论出于何种原因)需要Mercurial。顺便说一句:我对你的答案投了赞成票。谢谢沃克和彼得。这个命令正在神奇地工作。谢谢你的帮助。下面是主要功能
package main

import (
    "fmt"
    "net/http"
    "strconv"

    "golang.org/x/net/websocket"
)

var addr = "12345"

func EchoLengthServer(ws *websocket.Conn) {
    var msg string

    for {
        websocket.Message.Receive(ws, &msg)
        fmt.Println("Got Message", msg)
        length := len(msg)
        if err := websocket.Message.Send(ws, strconv.FormatInt(int64(length), 10)); err != nil {
            fmt.Println("can't send message length")
            break
        }
    }
}

func websocketListen() {
    http.Handle("/length", websocket.Handler(EchoLengthServer))
    err := http.ListenAndServe(addr, nil)
    if err != nil {
        panic("ListenAndServe:" + err.Error())
    }
}

func main() {}