search

Home  >  Q&A  >  body text

redis - goalng编译时找不到包

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文件的
一直编译不成功,请问这个是什么情况?

黄舟黄舟2798 days ago701

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-21 11:00:03

    ——! Got it, it contains directories instead of files, so the imported library should be

    github.com/alphazero/Go-Redis/
    

    But report this

    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.
    

    It’s probably a version limitation, I’ll try another redis library

    ======================update again======
    Changed the github.com/fzzy/radix/redis library and compiled it with its test code.
    Various problems on windows...

    reply
    0
  • Cancelreply