I have a fairly large project in github that I would like not to download in its entirety. The file is mostly Go based. Unfortunately, most of the file's packages call each other. I would like to use some of the files within this repo to test my code before I push it with the rest. Is their any way to import it into golang without downloading the file (using go get github.com/foo)?
As stated above, I've tried using go get github.com/etc. but it's way to large for that.
There's no tool I know of that could do this. You could use go list -f '{{ .Imports }}' or similar to list the dependencies you need for any given Go package, and script a way to download only the files needed. But you also have to think about things like templates or config files that your programs might access too.
Alternatively, and I have no idea if this will work, you could try mounting your Git repository as a FUSE mount. I found this in a quick Google search. This will let you download the files you need on demand, and of course when you compile your program, it will only include the code needed.
Related
I'm trying to generate the documentation for my packages in Golang. Ultimately I want to generate the documentation as part of CI/CD and host it inside our network. I know about godoc and using the instructions here I tried exactly as it states, in my package directory, however all I get is the full documentation for go itself, but not custom packages.
If I go to :6060/src, I can see a list of the contents of the src directory, and within that, I can see
However when I click on it, I get the response
I don't know if that's why I cant see my packages in the documentation, it would seem odd as $GOPATH is set to Users/me/go.
But if that's not related, how can I generate the static html files for specific packages such as my own? It seems much harder to google an answer for this that I expected. I know other tools use doxygen, but godoc doesn't seem equivalent in any way
I'm writing my first Go code which among other things, sends an email. After finding out that the package net/smtp only supports Plain Auth (but some providers like outlook doesn't support it), I asked for a solution and got pointed out to https://gist.github.com/andelf/5118732.
That code works like a charm, but as it's not something written by myself, I would like to add it in a separate file and just reference it in my main.go.
What's the right approach to have multiple files in the same package? I don't want to create a different package just for that code, first because it's not mine, and secondly, because I think it's an "overkill" approach, isn't it?
I thought that as long as the files are in the same directory, I could have many *.go files, but it seems it's not working out. If I just create a file with the content of that gist, the compiler fails because expected package, found import. If I add something like package auth, then it fails because found packages auth (auth.go) and main (main.go)
So, what's the general practice in this situations? Just create packages for everything?
You can have only one package in a directory, and it looks like you don't need a package for this addition, so you can simply put that in a separate file, and add package main at the top. Having a main package and putting everything under it works up to a point. As things get larger, you have to break it up into self-contained packages.
If your current working directory is in GOPATH, then you can just add new go file with same package name main.
If your current working directory is not in GOPATH, you can still put them in multiple go files and when you run the program, you should use go run *.go instead of just go run main.go.
There are also other options which you can refer Run code with multiple files in the same main package in GoLang for detail.
I"m trying to contribute for a project and the docs tell me to use this command
go get github.com/foo/bar
but the error is
can't load package: package github.com/foo/bar: no Go files in /home/f/go/src/github.com/foo/bar
Obviously its looking on my computer but how do I make it so that it downloads from the web?
The problem is that the project you're trying to download cannot be built, because Go can't find any source files to build at the source path github.com/foo/bar. The package is, however, downloaded, and if you look in $GOPATH/src/github.com/foo/bar you will see the repository cloned there. So if you want just that, then you're done, but you can use go get -d in the future to avoid the error message.
If you want something specific that can be imported, e.g. github.com/foo/bar/somepackage, then you should use go get github.com/foo/bar/somepackage.
I can specify dependencies to be downloaded by go get after checking out my project by importing them. I can even force the download of packages that are not used in the code by importing them for side effects:
import _ "github.com/jteeuwen/go-bindata"
Furthermore, on the shell I can apparently install a program with go get by using an ellipsis after the path:
$ go get github.com/jteeuwen/go-bindata/...
However, it seems I cannot combine both techniques:
import _ "github.com/jteeuwen/go-bindata/..."
$ go get
main.go:9:8: open c:\gopath\src\github.com\jteeuwen\go-bindata\...: Access denied
I would like to tell go get that for building (actually go generateing) this project, go-bindata has to be installed. Is it possible to specify install-dependencies?
To answer your question: No.
But you could vendor go-bindata into your project which would make it available after after go geting your project.
But maybe there is a slight confusion about when and why to run go generate: The intended use for go generate (as I understand it) is for package or command authors to generate code during the development phase. Code which is checked in and processed "normally" by go {build,install,get}. So you run go generate, check in the generated stuff and users of your package go get it and do not run go generate. They don't need to, the code comes in the proper checked in version during geting.
For more complicated builds which a end-user has to perform: Use Makefiles or similar tools as such stuff is out of the scope of go get.
In one of my projects I use Godep. According to its page:
This tool assumes you are working in a standard Go workspace, as
described in http://golang.org/doc/code.html. We expect godep to build
on Go 1.4* or newer, but you can use it on any project that works with
Go 1 or newer.
You'll have your dependencies in a JSON file, just like Node, Bower, etc... It's vert simple to use.
In your case, assuming you already have go geted the package, run:
godep save
This will generate the JSON file with all your other dependencies and save to a folder in your project. Thanks to it I was capable of cross compiling my project.
I have some huge images in a folder on the web version of Dropbox that I need to make a shell script to download them one by one (There isn't enough room on my SDD and can't download the whole folder). I know using "wget" I can download a file:
wget link_to_the_file
However since I have many images it is not feasible to get the download link of each of them manually. I'm looking for a way of obtaining downloading link for each of them through the shell. Any suggestions?
Dropbox offers an API you can use to write a program to list and download multiple files.
For instance, you can use /2/files/list_folder[/continue] to list files, and then use /2/files/download to download them.
Those are links to the HTTPS endpoints, but there are corresponding native methods in the official SDKs, if you want to use one of those.