Does not make sense that I have to have files before import

后端 未结 3 1693
無奈伤痛
無奈伤痛 2021-01-14 07:55

How do I import an external package from scratch?

I\'ve written a library package in Go and testing to distribute through github. I am following http://golang.org/do

3条回答
  •  滥情空心
    2021-01-14 08:55

    That's how I done it:

    1. Setup your workspace first

     mkdir $HOME/go
     export GOPATH=$HOME/go
     export PATH=$PATH:$GOPATH/bin
    

    2. Create the project

     mkdir -p $GOPATH/src/github.com/user
     mkdir $GOPATH/src/github.com/user/hello
     touch $GOPATH/src/github.com/user/hello/hello.go
    

    3. Install it

    go install github.com/user/hello
    

    4. Run it

    cd $GOPATH/bin
    ./hello
    

    I used the following vagrant image: https://github.com/dcoxall/vagrant-golang

提交回复
热议问题