One of the main use cases of the Go language with Elements is to use functionality from one of the countless existing Go libraries in your own project. Of course, it is always possible to just add the
.gosource files to your project directly, but for using complete libraries there's an easier way: Go Imports.
The EBuild command line tool offers a special option to import a Go library project – along with all its dependencies – from a git repository, create one or more
.elements projects from it for you, and build it — so that all that is left for you to do is add a Project Reference to the project where you need it.
This mode of EBuild is run by specifying the
--import-go-project command line switch, alongside the URL of the Go project (same as you would pass it to "
go get") and a set of additional parameters. e.g.:
ebuild --import-go-project github.com/nakagami/firebirdsql
How the Import Works
The import will determine the base URL of the repository specified by the URL. Supported are GitHub repositories,
gopkg.in URLs, as well as any valid git URL or any URL that supports the
It will clone that URL into a folder underneath the output folder and generate a
.elements project containing all
.go files within the specified subdirectory.
It will then check the
import sections of all these
.go files for additional external dependencies, and repeat the same steps, recursively if necessary, until all dependencies are covered.
.elements project will be generated for each repository; if imports dependencies request subdirectories of the same repository, the project for that repository will be extended to include the additional files.
Optionally, the root project and all its dependencies will be build using a regular EBuild build run, as the final step.
Once imported, you can use the generated main
.elements file in a Project Reference from your actual projects. (I would recommend against openign the imported projects in an IDE, because the solution can cecome huge for some imports, we;'re talking hundreds ot projects).
Read more about Go Imports on our docs site here.