Giter Site home page Giter Site logo

go-api-std's Introduction

go-api-std

Go APIs using as much of the standard library as possible.

Please note this is project is a playground for me while learning Go. ๐Ÿ˜„

Quickstart

Start Docker Desktop, or similar. Then run...

brew install golang-migrate

make dbup
make createdb
make migrateup

make swagger

make server

Features

  • REST server.
  • Dummy store (with in-memory db), used by unit tests.
  • Postgres store.
  • Migrations via golang-migrate.
  • Hashing of passwords.
  • Swagger
    • Generate JSON/YAML via github.com/swaggo/swag
    • Serve /docs via github.com/swaggo/http-swagger

Architectural choices

  • Layered API design:
    • domain, models and stores
      • services
        • rest
  • Custom errors are defined in the domain layer and can be used throughout the layers (but not useful in the rest layer).
  • In the rest layer, the custom domain errors are translated into http errors (using an error-to-status mapper).
    • When using this mapper, you must define the http status codes you are willing to have your route return, so to prevent the endpoint to start returning new error codes unexpectedly, following e.g. domain logic refactorings. Could also potentially make it easier to keep endpoint docs in sync with the code.
  • Ultimately, you should be able to tell from each rest server method which possible http status codes can be returned.

Todo/WIP:

Error handling

  • In API route functions, pass any error through the error-to-response mapper so to return a valid API error response.
  • In service functions, wrap any errors with a suitable domain error and return them to the API route functions.
  • In any other functions, just return regular, normal, errors.

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.