itang / todo.itang.me

4 stars 2 forks source link

试用gopm #13

Closed itang closed 11 years ago

itang commented 11 years ago

https://github.com/gpmgo/gopm go的项目管理工具(类似maven)

安装

$ set https_proxy=localhost:8087

for: "package code.google.com/p/snappy-go/snappy: Get https://code.google.com/p/snappy -go/source/checkout?repo=: dial tcp 74.125.128.113:443: ConnectEx tcp: A connect"

$ go get github.com/gpmgo/gopm

Usage

$ gopm get github.com/itang/gotang

将包下载并安装到~/.gopm/repos, 变成全局的package (目前的版本好像不支持package版本的管理(指定)?)

如果源码中引用的包已经存在于全局包,则copy当前项目的vendor目录下, 否则会自动gopm get并copy 到vendor目录

然后gopm 就替代go命令用于项目的构建,安装,测试了

....

main.go

package main

import (
  "fmt"
  "github.com/itang/gotang"
)

func main() {
  fmt.Println("sss")
  gotang.Assert(true, "")
}

$ gopm run main.go

[TRAC] Downloading package(github.com/itang/gotang => branch:<UTD>)
[TRAC] Downloading package(github.com/bmizerany/assert => branch:<UTD>)
[TRAC] Downloading package(github.com/kr/pretty => branch:<UTD>)
[TRAC] Downloading package(github.com/kr/text => branch:<UTD>)
[TRAC] Downloading package(github.com/kr/pty => branch:<UTD>)
[SUCC] Downloaded package(github.com/kr/pty => branch:<UTD>)
[SUCC] Downloaded package(github.com/kr/text => branch:<UTD>)
[SUCC] Downloaded package(github.com/kr/pretty => branch:<UTD>)
[SUCC] Downloaded package(github.com/bmizerany/assert => branch:<UTD>)
[SUCC] Downloaded package(github.com/itang/gotang => branch:<UTD>)
[INFO] linked github.com/itang/gotang
[TRAC] set GOPATH=D:\test\testgopm\vendor
[INFO] running ...
sss
[TRAC] set GOPATH=E:/workspace/gopath
[SUCC] run successfully!

疑问

从run的提示上看到: [TRAC] set GOPATH=D:\test\testgopm\vendor

vendor目录是项目的GOPATH

有点要深究的是项目本身源码的gopath如何算, 如何go-get-able??, 以当前项目的根目录为准吗?? 比如:

package main

import (
    "fmt"
    "github.com/itang/test"
)

其中github.com/itang/test 是项目本身要提供的包(go-get-able)

尝试1: 项目的包尝试类似放在vendor/src/github/itang/test, gopm还是会去网上下载,提示出错

尝试2: 放在项目_HOME/github.com/itang/test下, 也会像尝试1一样的结果

gopm没有把项目根目录当成GOPATH, 个人觉得如果跟目录当成GOPATH,貌似可以解决go-get-able的问题:

project/
   src/
       github.com/
       itang/
           test/
               .git