Simple-Implementation-JWT-Golang
Simple Implementation JWT Using Golang (Iris Framework) with Go Mod as Programming Language
This repository created to show the example for using JWT with this library dgrijalva/jwt-go
Directory structure
Your project directory structure should look like this
+ your_gopath/
|
+--+ src/github.com/moemoe89
| |
| +--+ simple-implementation-jwt-golang/
| |
| +--+ main.go
| + api/
| + routers/
| + ... any other source code
|
+--+ bin/
| |
| +-- ... executable file
|
+--+ pkg/
|
+-- ... all dependency_library required
Requirements
Go >= 1.11
Setup and Build
$ mkdir -p src/github.com/moemoe89
$ cd src/github.com/moemoe89
$ git clone <url>
$ mv <cloned directory> simple-implementation-jwt-golang
Demo
Use this host https://simple-jwt-golang.herokuapp.com/
Running & Using Application
Make sure you already have POSTMAN
> Running the application using `go run main.go`
> Open your POSTMAN.
> Fill the url with localhost:8789/generate and choose GET method
> You will get the response below :
{
"message": "Successfully generated token.",
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmVkX3RpbWUiOjE0Nzk0NDExNTEsInRoaXJkX3BhcnR5IjoibW9tbyJ9.P5sZwzCJD1DYptpuCp4hIyY5pGGnOB7m6ZHHi_mBEi4"
}
> For checking the token, fill the url with localhost:3000/parse and choose GET method. Fill the Header variable with Authorization and the value with token that you've get. You will get the response below :
{
"data": {
"third_party": "momo",
"expired_time": 1479441229
},
"message": "Successfully parsed token.",
"success": true
}
Running with Docker
$ docker build -t simple-implementation-jwt-golang .
$ docker run -d -p 8789:8789 --name simple-jwt-go simple-implementation-jwt-golang
How to stop the docker
$ docker ps
Copy the CONTAINER ID
$ docker stop {$CONTAINER_ID}