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文件的
一直编译不成功,请问这个是什么情况?
大家讲道理2017-04-21 11:00:03
— —!知道了,包含的是目录而不是文件,所以import的库应该是
github.com/alphazero/Go-Redis/
但是报这个
C:/Go/bin/go.exe build [C:/go_test]
# _/C_/go_test
.\re.go:6: import C:\Go_path\pkg\windows_amd64/github.com/alphazero/Go-Redis.a: object is [windows amd64 go1.1.2 X:none] expected [windows amd64 go1.2 X:none]
错误: 进程退出代码 2.
大概是版本限制,我换个redis库再试试
======================update again=====
换了github.com/fzzy/radix/redis库,用他的测试代码编译好了。
windows上各种问题...