A complete REST API server written in golang / go
A complete example of a REST-ful API server in written in Go (golang).
gorilla/contextfor per-request context
usersand
sessionsresources.
model,
controllerand
datalayers
serverpackage
usersand
sessions
Accept=application/json;version=1.0,*/*
usersand
sessions
gorilla/contextfor per-request context
unrolled/render; extensible to XML or other formats for response
server; 100% code coverage
ginkgofor test framework; optional.
See CHANGELOG.md for changes
To run an instance of a server example:
# get go-package and put it in your go-workspace go get github.com/sogko/slumbergo to package root folder
cd $GOPATH/src/github.com/sogko/slumber
install dependencies
go get
run Server
go run main.go
http://localhost:3001
# production go get github.com/codegangsta/negroni # HTTP server library go get gopkg.in/tylerb/graceful.v1 # graceful server shutdown go get github.com/gorilla/mux # HTTP router go get github.com/gorilla/context # Per-request context registry utility go get github.com/unrolled/render # JSON response renderer go get gopkg.in/mgo.v2 # Golang MongoDB driverdevelopment / test
go get github.com/onsi/ginkgo # Golang BDD test framework, complements
go test
go get github.com/onsi/gomega # Ginkgo's preferred matcher library go get github.com/modocache/gory #factory_girl
for Go
Install all Go package dependencies and run either one of the following command
go testor
$GOPATH/bin/ginkgo -r --randomizeAllSpecs -p -nodes=4
"-r" watches recursively (including test suites for sub-packages)
"-p -nodes=4" parallelize test execution with 4 worker nodes
$GOPATH/bin/ginkgo watch -r -p -nodes=4"-r" watches recursively (including test suites for sub-packages)
"-p -nodes=4" parallelize test execution with 4 worker nodes
Coveralls.io link: [https://coveralls.io/r/sogko/slumber]
To generate coverage profile
cd $GOPATH/src/github.com/sogko/slumberrun test recursively and generate coverage data for each package
$GOPATH/bin/ginkgo -r -cover -p
join coverage data for all packages into a single profile (for coveralls.io)
$GOPATH/bin/gover . slumber.coverprofile
To view coverage
go tool cover -html=$GOPATH/src/github.com/sogko/slumber/slumber.coverprofile
To generate key pair for signing JWT claims
bash $ openssl genrsa -out demo.rsa 1024 # the 1024 is the size of the key we are generating $ openssl rsa -in demo.rsa -pubout > demo.rsa.pub
Accept=application/json;version=1.0,*/*