How do I rebuild native Golang packages after I modify them? - go

I modified the net package and I want to use the modified version in my application but it keeps using the old code.

This works:
$ go install -a net
It wasn't rebuilding for me either, but the -a forces a rebuild even if the toolchain thinks the specified package is up to date.

In case someone is using Docker:
My changes wasn't having effect because I was editing the package outside the container. Only the code of our project is mapped by a volume inside the container, but not the third party packages.
Once I edited the package code inside the container, I do not even had to run a go install -a ... like proposed by #elimisteve. It worked just by recompiling the project.

Related

Installing Julia packages using a .toml file?

I am totally new to Julia!
I would like to install a large number of packages for a project I'm joining.
The project comes with a "Project.toml" file
It seems like there should be a nice way to install all the packages I need for the project, perhaps using the Project.toml file
However, I have not yet found any site that indicates how I might be able to do this.
Could anyone please let me know if what I am doing is possible, and if so, point me to a reference that would show how?
If your Project.toml is located in a folder, like myproject/Project.toml, you can simply start Julia with julia --project=/path/to/myproject, and it will automatically detect the Project.toml file in myproject.
The first time you activate this project, in the REPL, you can switch to Pkg mode by typing ], and type the command instantiate. This will cause the package manager to download and install all of the packages listed in Project.toml and their dependencies.
Another way to switch between projects during interactive use is to run activate /path/to/myproject in Pkg-mode in the REPL.
How to install julia packages from a Project.toml
First, you will have navigate to the folder containing your Project.toml.
cd ../your-folder-containing-the-project.toml-file
in your terminal:
julia --project=.
]
instantiate
or
julia --project=. -e 'using Pkg; Pkg.instantiate()
The other answers went already to the point, but I want to add another important aspect.
If this project comes "only" with a Project.toml file, you will be able to install "sone version" of these packages, eventualy the Project.toml may also give you a range of versions known to work with the project you have been given.
But if this project comes also with a Manifest.toml file you will be able to recreate on your pc the exact environment, will all the exact versions of all dependent packages recursivelly, of the guy that passed you the project, using the ways desctibed in detail in the other answers (e.g. ] activate [folder]; instantiate).

go install c shared output path

i'm trying to install a library inside a package. However I don't understand where it compiles to.
Structure is like so:
package/cmd/library
I can install other executable targets fine with go install. My paths are set correctly. However now I want to build my shared library target and deploy it somewhere (this deployment step can be done manually). I'm running into two different issues.
Issue one, I can't seem to install it at all:
go install -buildmode=c-shared bpackage/cmd/library#latest
Returns with:
go install: no install location for directory /home/tpm/go/pkg/mod/package/cmd/library outside GOPATH
For more details see: 'go help gopath'
which tells me that it installs somewhere other than in my gopath, I'm just not sure where that might be.
Issue 2, using the -o flag doesn't work with go install, so I can't seem to alter the output location to place it inside the GOPATH (i did try setting the GOBIN to within my gopath, but since other commands work fine I don't think this should be causing any issue)
Quoting Ian from https://github.com/golang/go/issues/24253
Note that it doesn't make a great deal of sense to use go install -buildmode=c-shared. The expectation is that people will use go build -buildmode=c-shared -o foo.so. The only point of using -buildmode=c-shared is to use the shared library somewhere, and using go install without -o will put the shared library in a relatively unpredictable place.

Is it possible to update local packages without running go install?

I am trying to import a local file into my main.go file and this tutorial (and other similar tutorials) says to run go install <path> in order to import that path as a package. This seems like a slow way to develop local packages because you would have to run go install <path> every time you want to see the changes in your local package.
Is there a faster way to import/update local packages? I am using gomon to auto-reload my code after updating it, so ideally, my code would auto-reload after updating a local package.
You should use go modules. The tutorial you mentioned appears to be older than the modules feature. In short: you can import a package, run go build, and any imported external package will automatically be downloaded for you as needed, no need to do a go get. Start here:
https://blog.golang.org/using-go-modules
https://github.com/golang/go/wiki/Modules

Issues installing a go program

Im new to go and I have been unable to find any thing online for my issue.
I have downloaded this code https://github.com/hashicorp/http-echo and I would like to set it up so I can run this command.
$ http-echo -listen=:8080 -text="hello world"
I have been getting quite a few different path issues.
Currently I have the code sitting in this directory.
/Users/jon/go/src/github.com/hashicorp
When I try and install it I get this error
$ go install http-echo
can't load package: /usr/local/go/src/http-echo/handlers.go:9:2: non-standard import "github.com/hashicorp/http-echo/version" in standard package "http-echo"
Where should I keep go projects on an OSX computer, and how do I get this to install or compile?
The code currently seems to be in /usr/local/go/src/http-echo. Packages should always reside in the directory $GOPATH/src/package-name, e.g.: $GOPATH/src/github.com/hashicorp/http-echo. (unless you're using go modules).
It should work if you move the source to the correct path (/Users/jon/go/src/github.com/hashicorp/http-echo). Then execute:
go install github.com/hashicorp/http-echo
Even easier would be to use go get to download the package in the first place. Simply run the following command from any directory:
go get github.com/hashicorp/http-echo
And http-echo is automagically installed.
If you still get an error after this, make sure $GOPATH/bin is in your $PATH.

the "hero" component of iris not installed when using "dep" to manage project dependencies

this question also posted here: https://github.com/kataras/iris/issues/1081
I am using "iris" as the MVC framework in my golang project, and i use "dep" to manage the dependencies of my project.
the "iris" dependency was configured in "Gopkg.toml" as bellow:
and later i use "dep ensure -v" to download all the dependencies.
after the "ensure" command finished, i check the downloaded files in "vendor/github.com/kataras/iris/hero" folder, i found there is no source code files were downloaded, refer to the screen capture bellow:
so i cannot use "hero" component in my project, because the "hero" related package not installed in my project.
thanks all for your help ~
I'm very new to Go; but I had a similar issue with another library 'https://github.com/jedib0t/go-pretty'
$ dep ensure -add github.com/jedib0t/go-pretty
"github.com/jedib0t/go-pretty" is not imported by your project, and has been temporarily added to Gopkg.lock and vendor/.
If you run "dep ensure" again before actually importing it, it will disappear from Gopkg.lock and vendor/.
The repo is cloned into pkg/dep/sources/https---github.com-jedib0t-go--pretty/ however there is no Go code in vendor/github.com/jedib0t/go-pretty/
I added an import "github.com/jedib0t/go-pretty" into one of my source code files and ran dep ensure -v however the vendor copy does not have any Go code it it. I removed the folder and tried again however same result.
What solved it for me was specifically importing the package I wanted into my code eg: "github.com/jedib0t/go-pretty/table" and running dep ensure -v again. I'm not sure why it worked but maybe my experience can help you or someone else.

Resources