Giter Site home page Giter Site logo

go-jwt-auth-api's Introduction

go-jwt-auth-api

A simple API using Go Fiber to provide JWT authentication. Also a simple Kubernetes config to spin up all that

curl -X POST http://localhost/login \
   -H "Content-Type: application/json" \
   -d '{"user":"rodolfo","pass":"bandeira"}' \
curl --location --request GET 'http://localhost:3000/restricted' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6dHJ1ZSw\
iZGV0YWlscyI6IkFueSBkZXRhaWwgZm9yIHRoZSB1c2VyIGNhbiBiZSBhZGRlZCBoZXJlLiA6KSIsImV4cCI6MTYz\
ODY1MzA0MCwibmFtZSI6IlJvZG9sZm8gQmFuZGVpcmEifQ.df-CWh_coFlMaShQCSv3WdscpL_Q_EEUhGJIvfsQ9Wd\
JHf9NzWwj6OmGTlHWKne-UXGcHHmKxIy8arzGAH5eZldiYTd_8STsFxXldXpFWWtsQYheOA1J7s4OtzN2LRiTNuz\
si5jf3ZByrrTUtZJEfuxzZQ24UAF22EZ5DE8P7FjAjGP1NxD44LXSAqrhZkPRESjze77q-y2HvvlUYD8K3pkgvvt\
1we6bx3dvLmOpHy_aXv76bEXX1whQ5JVDIJwSHMtmjxha2G118afZxH89Fy0xI182nfvPpKxIh6Ib-H2ZT0gcXxF\
ShimobhGoHyxkScqYUdrsqBeGI1chyEI_Qg'

Kubernetes in local enviroment:

minikube start

# Starting the Golang App API pod running on port 3000
kubectl apply -f k8s/deployment.yml

# Checking pod status:
kubectl get pods

# Creating a service of the type "NodePort". NodePort will
# make the external world able to access the cluster through this service
# using the "minikube ip" and the specific port
kubectl apply -f k8s/service-nodeport.yaml

# Checking which port should we use:
kubectl get services | grep NodePort
# service-nodeport   NodePort    10.107.102.51   <none>        8080:30003/TCP   70m

# Finally, accessing the pod App API passing through the NodePort service, and all this,
# from the external world (outside the cluster access):

# Get the network IP to access externally (From laptop)
minikube service service-nodeport --url
# http://192.168.49.2:30003

curl http://192.168.49.2:30003

# Scaling to 10 pods:
kubectl scale=10 -f k8s/deployment.yml

# Downgrade to 2:
kubectl scale --replicas=2 -f k8s/deployment.yaml
# deployment.apps/pod-api-app scaled


kubectl get pods
# NAME                          READY   STATUS    RESTARTS   AGE
# pod-api-app-598c8fc75-2gvh8   1/1     Running   0          4m46s
# pod-api-app-598c8fc75-5ct8z   1/1     Running   0          4m5s


# Running a MySQL (MariaDB) server:
kubectl apply -f k8s/db.yaml
kubectl exec -it db -- bash
mysql -u user -p
# user_password
# MariaDB [(none)]> show databases;
# +--------------------+
# | Database           |
# +--------------------+
# | information_schema |
# | my_db              |
# +--------------------+
# 2 rows in set (0.000 sec)

go-jwt-auth-api's People

Contributors

rodolfobandeira avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.