"Git Basics" was retired on February 8, 2019. You are now viewing the recommended replacement.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Here's how to organize your source code into packages. We'll also show you how to download and install new packages automatically, using the "go get" tool.
Your OS's $GOPATH
environment variable should be set to a directory where you will keep all your Go packages. Once that's done, from your console/terminal, run this command:
go get github.com/treehouse-projects/go-intro/welcome
That will visit this GitHub project and download a file with the below contents at $GOPATH/src/github.com/treehouse-projects/go-intro/welcome/welcome.go
:
package welcome
const English = "Welcome"
const Japanese = "ようこそ"
// Below languages not yet approved by committee
const klingon = "yI'el"
Once you've set up the welcome
package, you can use the package by creating another file named print_welcome.go
in the current directory with the following contents:
package main
import (
"fmt"
"github.com/treehouse-projects/go-intro/welcome"
)
func main() {
fmt.Println(welcome.English)
fmt.Println(welcome.Japanese)
}
Downloading a package from the Go team
The Go team has made this example package available on GitHub. You can download and install it by running:
go get github.com/golang/example/hello/reverse
Once you've done so, you can use the package via the following code:
package main
import (
"fmt"
"github.com/golang/example/hello/reverse"
)
func main() {
fmt.Println(stringutil.Reverse("hello"))
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up