api_jwt

command module
v0.0.0-...-3ca2010 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2019 License: GPL-2.0 Imports: 12 Imported by: 0

README

Go Report Card

API_JWT

Purpose

This is a small API written in golang that implements JSON Web Token through several external libraries.

Usage

Create the sqlite3 database elsewere:

$ sqlite3 ~/db/users.db < users.sql

Before running the server, you need to get all the dependencies needed, this might take some minutes. Be patience.

$ go get ./...

Finally you can build the server and run it doing:

$ go build api_jwt.go
$ ./api_jwt -p 3001 -db=~/db/users.db

For testing purpose, you can try to access the API root first:

$ curl -v http://localhost:3001/

Accessing the restricted endpoint /admin needs that you get authenticated first:

$ curl -v http://testuser:supersecret@localhost:3001/auth

This will give you a JSON Web Token that will last 3 minutes. Finally, to use the token do:

$ curl -H"Authorization: BEARER YOUeXtrEmlY.LongJSONWEbToken" -v http://localhost:3001/admin

Building a Docker image

To run api_jwt as a docker container you can build the image using the Dockerfile provided. Build it with:

$ docker build -t api_jwt .

and then just run it:

docker run -v ~/db:/db --rm -p 3001:3001 api_jwt -p=3001 -db=/db/users.db

Docker compose

Once you have built the image you can run the project doing a:

docker compose up -d

Enjoy!! :)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL