Chapter 4 - Packages
Exercise 1: Importing Packages
We’ve set up a Go package at https://github.com/jaymcgavren/car
.
What command would you run in your terminal to download and install this package in your Go workspace?
$
Once you’ve installed the package, you’ll have the following files in your workspace:
go/src/github.com/jaymcgavren/car/car.go
go/src/github.com/jaymcgavren/car/headlights/headlights.go
go/src/github.com/jaymcgavren/car/stereo/amplifier.go
go/src/github.com/jaymcgavren/car/stereo/speakers.go
go/src/github.com/jaymcgavren/car/wheels/wheels.go
Write a program that imports all the above packages and calls all the functions they contain. You can include the program in your Go workspace, if you like, or just store it anywhere and run it with go run
.
The program output should look like this:
Opening door
Shining headlights
Playing music
Bwomp bwamp BWOOOOMP
Turning front wheels
Peeling out!
When you’re ready, have a look at the solution.