The Go track now supports (some) external dependencies

Summary

Previously on the Go track, you could only use the standard library to solve the exercises. Now we added support for some extra packages that you can use. This post gives a little bit more context about this change and what you can do to start using those packages.

Context

With most languages in exercism, you are limited to use the standard library of your language. This happens because of the test runners that run the tests against solutions submitted either via the online editor or the CLI. These test runners are docker containers, which for security reasons, run without network access.

When you use a dependency and then run the code or compile it, the tooling that comes with most languages will try to download that dependency on the fly before running the program. Since the test runners have no network access, this is not possible, which is why most languages in Exercism don’t support the use of external dependencies.

What we did to provide this support was to pre-download some dependencies and build them into the docker image, so they are ready to use even with no network access.

What are the dependencies supported?

You can see the list of dependencies supported and their respective versions by checking this file:

You can use all the dependencies in the require section and all their sub-packages. If we ever add support for more dependencies, you can use that file as reference. At the time of writing, the dependencies supported are:

Will more dependencies be supported?

We can always add more dependencies to the list. If you believe a dependency can be used to solve an exercise, let us know what that dependency is and what exercise(s) you think would benefit from it.

However, note that the goal of supporting dependencies is not to make exercises trivial by just using some packages that do everything. The goal here is to provide some functionality that would not be fun to write yourself and does not undermine the learning goals of the exercises.

How to use these dependencies

Currently, you can only use external dependencies if you submit your solutions via the Exercism CLI. This is because you’ll need to change and submit the go.mod and go.sum files of the exercise along with the .go files for your solution.

If you think one of the packages (or one of its sub-packages) listed above can help you solve an exercise, here’s what you can do:

  1. Let’s assume you want to use one of the functions in golang.org/x/text/cases.

    • This is a sub-package of golang.org/x/text, which is a supported dependency, so you can use it.
    • You can check the supported dependencies in this go.mod file.
  2. Check the version Exercism supports for that dependency.

    • Also checking the go.mod file, you can see the version supported is for golang.org/x/text is v0.3.7
  3. Add the dependency with its version to the go.mod file of the exercise you are currently solving.

    • You can do this by manually editing the go.mod file
    • Alternatively, run in the exercise’s directory:
      • go get <dependency>@<version> (e.g go get golang.org/x/text@v0.3.7)
  4. Solve the exercise using the dependency

  5. Make sure your go.sum for the exercise is current by running:

    • go mod tidy
  6. Submit your modified go.mod, go.sum and the .go files for the exercise:

    • exercism submit go.mod go sum <solution_files.go>
3 Likes

This is awesome. Great work! Thanks to everyone who made this possible :blue_heart:

1 Like

Nice work and thank you for the hard work! This is a great addition :raised_hands: