Golang requirements.txt equivalent
Asked Answered
E

2

21

Coming from a python/django world, it'd be great to have something like a requirements.txt equivalent for go/revel. How can I do this? I know I can just write a requirements.txt file and then do something like

cat requirements | xargs go get

But what if my requirements ALSO have requirements? The above command would attempt to "go get" them, and then they'd fail to build, since I don't have those requirements installed.

Is there something I'm missing?

Extensometer answered 28/8, 2013 at 6:54 Comment(2)
go get should grab all of the requirements needed for each package. You shouldn't need to specify them. Try it and see if it does what you require.See
Unlike Python or most other programming languages, Go has import statements in each source file which specify where the imported code comes from. That's why there is no seperate package-descriptor file needed. (This only comes into play when you need to specify version constraints, see github.com/golang/go/wiki/vgo which is the tool for that from Go 1.11 and 1.12 onwards.)Phenomenon
S
17

The command go get does exactly what you need: It finds all dependencies and downloads and installs the missing ones. Focus on "all": go get really traverses your dependency graph.

Have a look at the documentation:

https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them

The Go documentation is really clean, short and well written. I would recommend always to have a look at the documentation first before making assumptions which are based on experience with other tools or tool-chains.

They also provide useful blog posts, https://blog.golang.org/using-go-modules

Sideband answered 28/8, 2013 at 7:50 Comment(5)
The link you've shared doesn't explain how I can write my own dependencies, though. Also developers and users may have a diffferent set of dependencies.Cystotomy
@erikbwork Could you explain what "my own dependencies" are? And what do you mean by "different set of dependencies" of users and developers? Are you thinking of dependencies needed only by the test code? If so: Go get handles this (see command line flags) If you talk about additional tools needed (e.g. go generates relies on yacc or m4) then go get is not for you. Go get downloads and build Go packages from source, it is not a package manager or system provisioning tool.Sideband
I don't know go so I can't explain it in these terms to you. But usually modern software requires some additional packages, e.g. your program might parse yaml files. Then you need the go-yaml-library in version 3.1.5. If you've never written it down somewhere, I doubt that go getwill figure it out. The difference between devs and users is mostly stability. Devs may use version 3.4.5 instead of 3.1.5, because it contains all the new features, but it may break. Users get 3.1.5 with the latest release though, because it breaks less often.Cystotomy
@erikbwork You are talking about package management and there are lots of tools out there, some almost official. Such a discussion is unrelated to go get.Sideband
yes, but it's not unrelated to the question you are trying to answer here.Cystotomy
C
3

I just found that the kubernetes guys actually have created an overview page for themselves here.

Summary is this: Currently stable is Glide and the cool new toy is called dep

Cystotomy answered 28/6, 2017 at 13:42 Comment(1)
this is outdateed as of 2019Anytime

© 2022 - 2024 — McMap. All rights reserved.