Giter Site home page Giter Site logo

sleepymalc / todolist Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 50 KB

Toy Project with Golang(Gin), JWT, MongoDB, Rest, GCP, GKE, and Docker.

Go 98.93% Dockerfile 1.07%
gke gcp docker restful-api mongodb-database golang gin-framework jwt-authentication go mongodb

todolist's Introduction

TODO

A Small TODO list Project

Abstract

This project is based on the following elements: Golang, Gin Framework, JWT (JSON Web Token), Restful API, MongoDB, GCP (Google Cloud Platform), GKE (Google Kubernetes Engine). We use Postman to test all the API functionality. Additionally, one can build with Docker and push it to GKE and expose it to the internet.

Features

  1. users/signup: Post method

    Sample Input

    {
      "user_id": "admin",
      "password": "88888888"
    }

    Sample Output

    {
      "InsertedID": "60581eb9cc2216b508d7477d"
    }
  2. users/login : Post method

    Sample Input

    {
      "user_id": "admin",
      "password": "88888888"
    }

    Sample Output

    {
      "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VyX2lkIjoiYWRtaW4iLCJleHAiOjE2MTY0NzQxNjl9.aAlh_LuxqLfWWSzCd3uA3C2RoBOTnC3HSqPaAvzYIkE"
    }
  3. users/todo_list: Post method

    Sample Input

    {
      "todo_list": ["do homework", "write diary"]
    }

    Sample Output

    {
      "MatchedCount": 1,
      "ModifiedCount": 1,
      "UpsertedCount": 0,
      "UpsertedID": null
    }
  4. user/todo_list: Get method

    Sample Output

    {
      "do homework",
      "write diary"
    }

    Note that this method does not have input.

  5. user/todo_list: Delete method

    Sample Input

    {
      "delete_element": "do homework"
    }

    Sample Output

    {
      "MatchedCount": 1,
      "ModifiedCount": 1,
      "UpsertedCount": 0,
      "UpsertedID": null
    }

GCP + GKE

To build a docker file, first, go to /Todo_List, and then type in the following command:

> docker build -t asia.gcr.io/PROJECT_ID/todo_list .

which will generate an image of this project. To push the image to GCP, we type in the following command:

> docker push asia.gcr.io/PROJECT_ID/todo_list

which just pushes the image file to your GCP project. Now, to run the project o GKE, we use:

> kubectl run todolist --image=asia.gcr.io/PROJECT_ID/todo_list

which tells GKE to run the project. You can check if this is working by the following command:

> kubectl get pods

this will give you the current state of your pod. If the state is running, now you can enter the Docker by the following command:

> kubectl exec -it todolist -- bash

which will let you get into the docker. Finally, to expose your project to the Internet, use the following command:

> kubectl expose deployment todolist-server --type LoadBalancer --port 80 --target-port 80

which specifies both the exposed port in docker and the port of your localhost is 80, and also generates a load-balancer. Now, use the following command to truly deploy the project:

> kubectl create deployment todolist-server --image=asia.gcr.io/PROJECT_ID/todo_list

To get the IP of your project, use the following command:

> kubectl get service

To delete the service, use:

> tubectl delete service todolist-service

Postman

In the repo, you can find TodoList.postman_collection.JSON and then import to the Postman.

todolist's People

Contributors

sleepymalc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

syiham11

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.