Note
The GitHub repository for this book's source code is https://github.com/l3x/learn-fp-go.
If you store your Go projects in the ~/myprojects
directory, then run cd ~/myprojects; git clone https://github.com/l3x/learn-fp-go.git
.
Next, run the cd
command into the first project directory: cd ~/myprojects/learn-fp-go/1-functional-fundamentals/ch01-pure-fp/01_oop
.
Directories correspond to the book's units and chapters:
Note
You'll find an executable init
script file in all project directories. It's there to make your life easier. When you cd into a project directory, first source the init
script. You can do that by either typing source init
or . init
. (The dot (.) and source
commands are interchangeable.) The init
script will use Glide to install any dependencies for your project in a vendors directory.
For details see the How to build and run Go project section in the Appendix, Miscellaneous Information and How-Tos.
PS: Dependencies are third-party Go libraries that our Go application needs to run properly.
Let's run our first Go application as follows:
Each chapter is divided into sequentially numbered directories that are in the order of their appearance in the book.
First, let's make sure we have Go installed, our GOPATH
is properly set, and that we can run a Go application.
Note
If you are using a macOS, then check out the instructions on how to use the brew
command to install Go in the appendix; otherwise, to install Go, visit: http://golang.org/doc/install.To set your GOPATH
, visit: https://github.com/golang/go/wiki/SettingGOPATH.
Many people use a global GOPATH
to store the source code for all their Go applications or, frequently, manually reset their GOPATH
. I found this practice to be troublesome when working with multiple Go projects for multiple clients, each of which had differing Go versions and third-party dependencies.
The example Go applications that we'll use in this chapter do not have dependencies; that is, we don't have to import any third-party packages. So, all we have to do to run our first app--cars.go--is
verify that Go is installed, set our GOPATH
, and type go run cars.go
:
Using a global GOPATH
is easy for projects that are super simple, like the examples in this chapter.
In Chapter 2, Manipulating Collections, our Go applications will start getting more complex, and we'll get introduced to a simple, more consistent way to manage our Go development environments.