Giter Site home page Giter Site logo

monkey's Introduction

monkey

A Go implementation of an API Test CRM service.

Run command

go run monkey.go

Purpose of this exercise

  • Learn Go
  • Implement an API from scratch
  • Get to know the popular gin web framework
  • Set up authorization with OAuth 2.0
  • Exchange auth token with Google
  • Check if the ID token is a valid JWT
  • Avoid ORM libraries like GORM
  • Write raw SQL for schemas and queries
  • Get to know sqlc to compile SQL to type-safe code
  • Set up postgres running in podman
  • Use golang-migrate to generate migrations

Database setup

  1. SQL schema defines the Customer and User models
  2. query.sql defines the model relations
  3. sqlc.yml config file references the schema and query, along with the database engine and output files that will be generated
  4. sqlc generates Go structs that will be used in the Go program to interface with the database. These structs are type safe and protect against SQL injections
  5. Various .sh scripts document how to run commands that set up the database
  6. Containerized postgres runs on podman machine
  7. golang-migrate generates migrations
  8. Seed function populates the database initially

References

REST API

  1. gin for handling routes
  2. Handlers specify User and Customer routes
  3. Model structs are used in route actions, as a form of ORM
  4. Queries and auth middleware added to gin context

References

Authorization

  1. Set up project on Google Cloud Console, get client id and secret, set as ENV variables
  2. Inject auth middleware into gin context for specific routes
  3. Auth route handler handles the callback after authorization, gets id token and sets it in a cookie
  4. Auth middleware validates the id token and sets User as admin

References

monkey's People

Contributors

emilosman 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.