-
Notifications
You must be signed in to change notification settings - Fork 1
Introduction to Go
I'll be writing a little bit here to help people understand the server code. To start I'll put in some information about installing and setting up go.
Installing Go requires a little bit of setup, because it includes its own package manager and build system. The first step is to install Go using your system package manager. I recommend checking the version, because some libraries will not work with old Go versions (even though it is backwards compatible). I am using Go 1.7.
Next, create a directory for you go workspace (usually called go/
). Beneath it create three sub-directories called src/
, pkg/
, and bin/
. Keep all of your go projects in the src/
directory. When you call go install
, go builds compiles and builds a binary which it puts in the bin/
directory. pkg/
contains compiled packages and other build stuff that you don't need to worry about.
Finally, set up your PATH. Go uses the system path to find your source, package, and bin files. Adding the bin directory to your path also allows you to run go binaries by name.
My bashrc has these extra lines:
export GOPATH=$HOME/Documents/Go
export PATH=$PATH:$GOPATH/bin
When I want to compile and run I do:
go install
jimmify-server
Once you clone the server in to the /src directory you will need to run go get
in order to get the sqlite driver.
The current implementation has three "go packages". The main package at the root contains the main file which starts the server. The handlers package contains all of the individual endpoint handlers, and the DB package contains the database-specific functions. In the main package, something from the db package would be accessed using db.Whatever
.
The main thing that trips people up at first with go is the fact that it is case sensitive. A variable, attribute, or function will be exported (public) if it starts with a capital letter. Otherwise it is private to the package.
Beyond that everything is fairly straightforward.
I've implemented all of the endpoints with the functionality outlined in the API Documentation. There is no validation of input or restrictions however, so there's definitely more to do if people want to learn Go. I recommend beego/Validate for json validation.