Go + Gorilla codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
This codebase was created to demonstrate a fully fledged fullstack application built with Go + Gorilla including CRUD operations, authentication, routing, pagination, and more.
We've gone to great lengths to adhere to the Go community styleguides & best practices.
For more information on how to this works with other frontends/backends, head over to the RealWorld repo.
There are other GO implementations utilising the different web frameworks available to Golang developers.
- Go net/http (https://github.com/JackyChiu/realworld-starter-kit)
- Go + GIN (https://github.com/chrislewispac/realworld-starter-kit)
API route status
- Authentication (
POST /api/users/login
) - Registration (
POST /api/users
) - Get Current User (
GET /api/user
) - Update User (
PUT /api/user
) - Get Profile (
GET/api/profiles/:username
) - Follow user (
POST /api/profiles/:username/follow
) - Unfollow user (
DELETE /api/profiles/:username/follow
) - List Articles (
GET /api/articles
) - Feed Articles (
GET /api/articles/feed
) - Get Article (
GET /api/articles/:slug
) - Create Article (
POST /api/articles
) - Update Article (
PUT /api/articles/:slug
) - Delete Article (
DELETE /api/articles/:slug
) - Add Comments to an Article (
POST /api/articles/:slug/comments
) - Get Comments from an Article (
GET /api/articles/:slug/comments
) - Delete Comment (
DELETE /api/articles/:slug/comments/:id
) - Favourite Article (
POST /api/articles/:slug/favorite
) - Unfavourite Article (
DELETE /api/articles/:slug/favorite
) - Get Tags (
GET /api/tags
)
- More Tests
- Make simpler - maybe another branch to show simpler use of
func (w http.ResponseWriter, r *http.Request)
? - Better/simpler error / response handling - just
w.WriteHeader
on error - alice/negroni chaining?
- Optimise / Refactor / Data model Refining
- Docker?
- Vendor dependencies
See the wiki for more information.
- Installation instructions for Go: Getting Started
- Getting familiar with the environment: How to write Go Code
go get github.com/chilledoj/realworld-starter-kit
cd $GOPATH/src/github.com/chilledoj/realworld-starter-kit
TODO: Vendor dependencies
go get ./..
Currently this codebase is utilising MYSQL as the database. Ensure you have created the database and tables (mysql_init.sql
provided in models directory)
You can build using your own build flags, or use MAKE
as there is a makefile
provided.
make build
A run command is provided in the makefile
which will first run the build step.
make run
N.B. The database URL (containing user+pass+host+port) can be set as an environment variable, passed as a flag to the executable or set in the config.ini
file.
./bin/backend -dburl "root:password@/conduit?parseTime=true"
// or
DBURL=root:password@/conduit?parseTime=true ./bin/backend
// or -config config.ini
dburl=root:password@/conduit?parseTime=true
Additionally the IP host and ports are currently defaulted to run on ":8080", but can be passed in as ENV variables, command line flags or in the config.ini file: HOST or -host or host=
and PORT or -port or port=
.
N.B. See the flags package for more details on these are handled.
openssl genrsa -out server.key 2048
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
docker-compose up --build
The api will be available at https://localhost:8080
Raise an issue and/or Pull Request. Alternatively create your own better fork.