package
0.0.0-20240627205039-84df7b482785
Repository: https://github.com/umcloud/clases-devops.git
Documentation: pkg.go.dev

# 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

Enjoy!! :)