Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Follow this link to install golang https://golang.org/doc/install
Follow this link to setup $GOPATH env https://golang.org/doc/gopath_code.html
- Navigate to gopath directory by executing command
$ cd $GOPATH/go/src
- Clone the repository by executing command
$ git clone [your repository]
- viper
$ go get github.com/spf13/viper
- gorm
$ go get -u github.com/jinzhu/gorm
- goose
$ go get -u github.com/pressly/goose
- gqlgen
$ go get github.com/99designs/gqlgen
- uuid
$ go get github.com/satori/go.uuid
export dbhost=127.0.0.1
export username=[your username]
export password=[your password]
- config - configuration about the environment variables, database, files, etc. should be place in the folder
- graph - graphql server for golang
- data - database connection e.g. postgresql, mongodb, redis
- migrations - for migrating changes to the database
- models - domain model and table structure are the content of this folder
Create a database in PostgreSQL with the name:
sample_db
Go to go-graphql-api-starter/migarations
directory and execute the following command in the terminal:
- Create sql migration file
goose create [file name or migration description] sql
- Check the status of the migrations
goose postgres "user=[your user] password=[your password] dbname=psql_lookups_db host=127.0.0.1 sslmode=disable" status
- Update the migrations
goose postgres "user=[your user] password=[your password] dbname=psql_lookups_db host=127.0.0.1 sslmode=disable" up
- Downgrade the migrations
goose postgres "user=[your user] password=[your password] dbname=psql_lookups_db host=127.0.0.1 sslmode=disable" down
To run the API directly without creating executable, run the command in terminal:
$ go run server.go
- To create an executable file, run the command in terminal:
$ go build
- Execute the generate file by specifying the name e.g.
./sample-api
http://localhost:4000/