windows 7 64位係統,golang 版本1.2
go默認安裝在c:\Go
GOPATH為c:\Go_path
測試alphazero/Go-Redis,過程如下
文件位置c:\go_test\re.go,代碼如下:
package main
import (
"bufio"
"fmt"
"github.com/alphazero/Go-Redis/redis"
"log"
"os"
)
func main() {
spec := redis.DefaultSpec().Db(13)
client, e := redis.NewSynchClientWithSpec(spec)
if e != nil {
log.Println("failed to create the client", e)
return
}
key := "examples/hello/user.name"
value, e := client.Get(key)
if e != nil {
log.Println("error on Get", e)
return
}
if value == nil {
fmt.Printf("\nHello, don't believe we've met before!\nYour name? ")
reader := bufio.NewReader(os.Stdin)
user, _ := reader.ReadString(byte('\n'))
if len(user) > 1 {
user = user[0 : len(user)-1]
value = []byte(user)
client.Set(key, value)
} else {
fmt.Printf("vafanculo!\n")
return
}
}
fmt.Printf("Hey, ciao %s!\n", fmt.Sprintf("%s", value))
}
c:\go_path目錄下有pkg,src,bin,3個目錄
首先獲取redis包,執行如下命令
go get github.com/alphazero/Go-Redis/redis
獲取成功,如圖,
C:\Go_path\pkg\windows_amd64\github.com\alphazero目錄生成了Go-Redis.a
cmd進入c:\go_test\,執行
go run re.go
提示
c:\go_test>go run re.go
re.go:6:2: cannot find package "github.com/alphazero/Go-Redis/redis" in any of:
C:\Go\src\pkg\github.com\alphazero\Go-Redis\redis (from $GOROOT)
C:\Go_path\src\github.com\alphazero\Go-Redis\redis (from $GOPATH)
C:\Go_path\src\github.com\alphazero\Go-Redis\目錄確實有redis.go文件的
一直編譯不成功,請問這個是什麼情況?
— —!知道了,包含的是目錄而不是文件,所以import的函式庫應該是
但是報這個
大概是版本限制,我換個redis庫再試試
======================update again=====
換了github.com/fzzy/radix/redis函式庫,用他的測試程式碼編譯好了。
windows上各種問題...