Git Product home page Git Product logo

go-api-racon's Introduction

Go API RACON

This project is an end to end example api written in go. The example contains routing, route security, social authentication, jwt token handling, database connectivity, and tests which can be used to bootstrap your next go project. The project is intended to provide a more complete context for building an application in go than the examples for specific functionality can provide.

This project can be run in google app engine. This project can also be run locally or within a container using go's ListenAndServe().

This project is not intended to securely handle secrets. If you are running a publicly hosted project, don't rely on the environment variables in app.yaml or start.sh for project setup.

RACON: A radar beacon used to aid nautical navigation.

App Engine

To run this project in app engine, you will need to setup

  • a google cloud project
  • ouath 2 client
  • a cloud sql instance
  • app engine
  • a public/private key pair ( use ssh-keygen on mac )

Once these are setup, you can add the appropriate env variables to app.yaml and

./deploy.sh

will push the project to app engine.

Local development

To run this project locally, you will need to setup

  • a public/private keypair ( use ssh-keygen on mac )
  • ouath 2 client
  • a postgres instance

Once these are setup, you can add the appropriate env variables to start.sh and

./start.sh

will start a local server for the project.

Start local db container

The example uses postgres for the backend database which can be deployed locally with docker:

sudo mkdir /var/run/postgres
docker run -p 5432:5432 -v /var/run/postgresql/:/var/run/postgresql -v $PWD/local-app.sql:/docker-entrypoint-initdb.d/init-app-db.sql --name postgres -e POSTGRES_PASSWORD=pgpass -d postgres:latest
  • starts docker container locally w/ socket /var/run/postgresql, user postgres, db postgres
  • loads db from local-app.sql file

container deployment

Since the go http server is run from the main.go file, you can use this project to create a docker image. A dockerfile has not been included.

Key Components

router

  • This project uses chi because it's just a router. Gin also looked nice and has more recent github activity, but it handles a much wider range of functionality than needed for an API.

logging

  • This project uses zerologger because it has a decent API and it's reportedly fast. Being able to switch between a structured logger for deployment and a console logger for local development was also important.

Todo

  • Implement a connection to secrets manager as a better method of secrets management than env variables
  • More comphrensive testing

go-api-racon's People

Contributors

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