Skip to content
/ go-api Public

πŸš€ Example api for inspiration on your new projects

License

Notifications You must be signed in to change notification settings

mrz1836/go-api

Repository files navigation

go-api

Example API with support for common implementations

Release Build Status Report Go Sponsor Donate


Table of Contents


Installation

1) go-api requires Go, Redis and MySQL with no password set

go get -u github.com/mrz1836/go-api
make install

2) Run the API

make run

  "starting Go API server..."

Test your connection to the api

curl -X GET 'http://localhost:3000'

  "Welcome to the Go API!"

Documentation

View the generated documentation

GoDoc

Features

  • Combination of powerful Go packages all-in-one API solution
  • The fastest router: Julien Schmidt's httprouter
  • The best redis cache package: Gary Burd's Redigo
  • Powerful database ORM: VolatileTech's SQLBoiler
  • Database migration: Pressly's Goose
  • Ready for development or production use
  • Cache dependency management via go-cache
  • Supports different incoming load balancer setups (/health)
  • Logging each request and whenever you need logs (remote via LogEntries)
  • Flexible environment & configuration management using viper
  • Built-in scheduler for any cron jobs or delayed tasks
  • Powerful and easy emailing with support for Postmark, Mandrill, AWS SES and SMTP
Package Dependencies
Library Deployment

goreleaser for easy binary or library deployment to GitHub and can be installed via: brew install goreleaser.

The .goreleaser.yml file is used to configure goreleaser.

Use make release-snap to create a snapshot version of the release, and finally make release to ship to production.

Makefile Commands

View all makefile commands

make help

List of all current commands:

all                  Runs multiple commands
clean                Remove previous builds and any test cache data
clean-mods           Remove all the Go mod cache
coverage             Shows the test coverage
db                   Creates a fresh database
diff                 Show the git diff
env                  Creates a fresh database
flush-redis          Wipe out all data in redis (requires redli)
generate             Runs the go generate command in the base of the repo
godocs               Sync the latest tag with GoDocs
help                 Show this help message
install              Install the application
install              Run the Custom installation
install-go           Install the application (Using Native Go)
lint                 Run the golangci-lint application (install if not found)
release              Full production release (creates release in Github)
release              Runs common.release then runs godocs
release-snap         Test the full release (build binaries)
release-test         Full production test release (everything except deploy)
replace-version      Replaces the version in HTML/JS (pre-deploy)
run                  Runs the application
run-examples         Runs all the examples
schema               Run the Model/schema generation
tag                  Generate a new tag and push (tag version=0.0.0)
tag-remove           Remove a tag if found (tag-remove version=0.0.0)
tag-update           Update an existing tag to current commit (tag-update version=0.0.0)
test                 Runs lint and ALL tests
test-ci              Runs all tests via CI (exports coverage)
test-ci-no-race      Runs all tests via CI (no race) (exports coverage)
test-ci-short        Runs unit tests via CI (exports coverage)
test-no-lint         Runs just tests
test-short           Runs vet, lint and tests (excludes integration tests)
test-unit            Runs tests and outputs coverage
uninstall            Uninstall the application (and remove files)
update-linter        Update the golangci-lint package (macOS only)
vet                  Run the Go vet application
Model Generation

Update the reset_api_database.sql if you have issues running the model tests

GRANT ALL ON `dynamic-database-name-generated-from-sql-boiler`.* to 'apiDbTestUser'@'%';

Rebuilding the generated models/schema from the database schema:

make schema

Clear local redis and reload the database

make db
make flush-redis
Environment Variables

All environment variables are referenced in the config.

Edit the scripts/set_env.sh file and modify the environment variables - IE:

export API_SERVER_PORT=3000

Examples & Tests

All unit tests and examples run via GitHub Actions and uses Go version 1.19.x. View the configuration file.

Run all tests (including integration tests)

make test

Run tests (excluding integration tests)

make test-short

Benchmarks

Run the Go benchmarks:

make bench

Code Standards

Read more about this Go project's code standards.


Usage

(Coming soon: Examples!)


Maintainers

MrZ
MrZ

Contributing

View the contributing guidelines and please follow the code of conduct.

How can I help?

All kinds of contributions are welcome πŸ™Œ! The most basic way to show your support is to star 🌟 the project, or to raise issues πŸ’¬. You can also support this project by becoming a sponsor on GitHub πŸ‘ or by making a bitcoin donation to ensure this journey continues indefinitely! πŸš€


License

License