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?

kramer65
  • 50,427
  • 120
  • 308
  • 488
mangoman
  • 219
  • 2
  • 4
  • 6
    `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. – Intermernet Aug 28 '13 at 07:02
  • 1
    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 https://github.com/golang/go/wiki/vgo which is the tool for that from Go 1.11 and 1.12 onwards.) – Robert Jack Will Jul 05 '18 at 17:21

2 Answers2

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

Volker
  • 40,468
  • 7
  • 81
  • 87
  • 1
    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. – erikbstack Jun 27 '17 at 09:03
  • @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. – Volker Jun 27 '17 at 09:22
  • 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 get`will 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. – erikbstack Jun 27 '17 at 13:23
  • @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`. – Volker Jun 28 '17 at 03:53
  • 2
    yes, but it's not unrelated to the question you are trying to answer here. – erikbstack Jun 28 '17 at 11:07
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

erikbstack
  • 12,878
  • 21
  • 81
  • 115