- Go - a programming language that is fast, uses minimal resources and supports high concurrency
- Gorilla Mux - minimalistic request router and dispatcher
- Gorilla Logging Handler - middleware for http request/response logging
- jwt-go - a jwt library for Go
- testify - testing and assertion library
- dep - the official dependency management tool for Go
- gin (optional) - livereload utility for faster development turnaround in local
- Go is installed. To verify, run
go version
- GOPATH is set (e.g. set to
~/go
) - PATH includes
GOPATH/bin
dep
is installed- to get it, run
go get -u github.com/golang/dep/cmd/dep
- to get it, run
- clone repo or download zip
- get the dependencies by running
dep ensure -update
in the project directory - in the project directory, run
go build && ./go-mux-jwt
- launch the browser and point to the baseurl
localhost:3001
- port can be changed in
main.go
- port can be changed in
- optional:
- use gin to monitor for changes and automatically restart the application
- if you don't have gin,
go get github.com/codegangsta/gin
- in the project directory run
gin
(no need to build or run executable, when you do this)
- if you don't have gin,
- update
Gopkg.toml
to use different version(s) for the dependency/vendor libs- run
dep ensure -update
after changing the toml file
- run
- use gin to monitor for changes and automatically restart the application
- to run the tests, run
go test
in the project directory - test coverage:
- to run tests and generate coverage report, run
go test -cover
. - percentage covered is shown in the terminal upon execution of this command
- to run tests and generate coverage report, run
- access the unsecure api
GET /metacortex
- all
/api/*
calls are secured with JWT authentication - try accessing the secure api
GET /api/megacity
to see an auth error - obtain a JWT token here:
/static/authenticate.html
- enter programName:programPassword (neo:keanu)
- the response contains a JWT token for that program
- use the token when calling any secure api (
/api/*
):- set the
Authorization
request header and add the jwt token, like so: Authorization: Bearer \<token\>
- set the
GET /api/megacity
can be accessed with any valid token butGET /api/levrai
can only be accessed with neo's token