go-api

command module
v0.0.0-...-7dc802a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go template API CircleCI

Eyecue Lab golang api template, could serve as a starting point when developing a Web API.

Features

  • Live reload with docker compose for local development
  • API with examples for creating routes and handlers
  • JSONAPI schema with custom actions definitions for the client app to avoid hardcoding
  • Optional setup to have a separate content management API
  • Reusable models between different APIs
  • Examples of how to preload related data
  • Postgres database migrations
  • Data seeding functionality for development and test database prep
  • Cron jobs setup for periodic tasks
  • Integrations with 3rd party apis: airbrake, sendgrid
  • Automated testing with Circleci
  • API endpoints integration tests examples
  • Models unit tests examples

Usage

Make commands rely on Docker Engine, please make sure you have it installed

To start API locally: make api and curl http://localhost:8000 | json_pp

To use all available endpoints, including sign in etc... you'll need to migrate and seed database, refer to make commands below:

Show more make commands
  • When adding new imports within the app, to update go.mod and go.sum, run:
make dep
  • Run database migrations:
make db_migrate
  • There are predefined fixtures like users, companies etc... inside cmd/storage, to seed database with that data:
make db_seed
  • Create a new database migration file:
make db_create_migration file=create_bananas
  • Drop dev database. This will stop docker volumes and delete the database volume, after running this command to get your database restored to use API, you'll need to run a migration and seed commands
make db_drop
  • Open psql console inside postgres container:
make psql_console
  • Run bash console inside API container:
make bash
  • Run API integration tests:
make test_api
  • Run models unit tests:
make test_models
  • There is a standalone Admin CMS API cmd/admin that uses the same Models layer as a main API, to start admin API:
make admin
  • Cron jobs example is in cmd/cron, to run cron jobs:
make cron

API Endpoints

List of existing API endpoints and curl examples

Show endpoints
  • Health check
curl http://localhost:8000/health
  • Versions
curl http://localhost:8000/version
  • Anon user init data. Provides data in jsonapi schema for a guest user
curl http://localhost:8000/ | json_pp
  • Sign In. Response headers will hold authentication jwt that can be used to call auth endpoints
curl -H "Content-Type: application/json" -X POST -d '{"email": "user1@example.com", "password": "goapi123"}' http://localhost:8000/login | json_pp
  • Authenticated user init data. Provides data in jsonapi schema for an authenticated user
curl -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoxfQ.VEy5T2jj4rIr2Sfs_mif0uKTi9GyX2eAi4_QYcL673o" http://localhost:8000/ | json_pp

TODO

  • Queue setup example
  • Protocol Buffer API
  • Generate docs, godoc
  • ...

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL