All Projects → zubroide → go-api-boilerplate

zubroide / go-api-boilerplate

Licence: other
Boilerplate for Golang API

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to go-api-boilerplate

Hotels server
酒店预订系统后台管理系统
Stars: ✭ 249 (+62.75%)
Mutual labels:  api-rest
express-generator
Boilerplate | ExpressJS server
Stars: ✭ 35 (-77.12%)
Mutual labels:  bolierplate
buscador-ao
Ponto de obtenção de informações públicas de Angola
Stars: ✭ 21 (-86.27%)
Mutual labels:  api-rest
nestjs-api-mongoose
Collection example apps with NestJS and Typeorm, Sequelize, Mongodb, PostgreSQL, MySQL, GraphQL, Mercurius, etc. for the NestJS community 😻
Stars: ✭ 153 (+0%)
Mutual labels:  api-rest
laravel5-jokes-api-with-jwt-and-pagination
Laravel5 Full Fledged API with JWT auth
Stars: ✭ 15 (-90.2%)
Mutual labels:  api-rest
covidAPI
Coronavirus API for Current cases by country COVID-19
Stars: ✭ 600 (+292.16%)
Mutual labels:  api-rest
Api on rails
Learn best practices to build an API using Ruby on Rails 5/6
Stars: ✭ 236 (+54.25%)
Mutual labels:  api-rest
cleanapi
Pretty tornado wrapper for making lightweight REST API services
Stars: ✭ 26 (-83.01%)
Mutual labels:  api-rest
openbrewerydb-rails-api
Official v1 Open Brewery DB REST API built with Ruby on Rails
Stars: ✭ 17 (-88.89%)
Mutual labels:  api-rest
webpack4-boilerplate
webpack4打包模板
Stars: ✭ 36 (-76.47%)
Mutual labels:  bolierplate
api sof
Tutorial para acessar a API do Sistema de Orçamento e Finanças _SOF da cidade de São Paulo, utilizando Python e a biblioteca Pandas, realizar análises e salvar arquivo CSV/Excel
Stars: ✭ 31 (-79.74%)
Mutual labels:  api-rest
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (-51.63%)
Mutual labels:  api-rest
The-Code-Bending-Dictionary
🧚🏽‍♀️ learn tech vocab in a friendly way 🧚🏽‍♀️ CONTRIBUTIONS WELCOME! 🔥
Stars: ✭ 19 (-87.58%)
Mutual labels:  api-rest
Webhookd
A very simple webhook server launching shell scripts.
Stars: ✭ 250 (+63.4%)
Mutual labels:  api-rest
vemdezapbe.be
Vem de zap bb 😏😊😂
Stars: ✭ 33 (-78.43%)
Mutual labels:  api-rest
Coinapi Sdk
SDKs for CoinAPI
Stars: ✭ 238 (+55.56%)
Mutual labels:  api-rest
dart-express
Express-like HTTP framework written in Dart
Stars: ✭ 34 (-77.78%)
Mutual labels:  api-rest
liuye
柳叶清单开放 API 文档
Stars: ✭ 32 (-79.08%)
Mutual labels:  api-rest
nuada-cli
Nuada CLI was designed to improve your development experience by using ExpressJS and Mongoose tools.
Stars: ✭ 19 (-87.58%)
Mutual labels:  api-rest
reedelk-runtime
Reedelk Runtime Platform Community Edition
Stars: ✭ 25 (-83.66%)
Mutual labels:  api-rest

Go API Boilerplate

Features

  • Framework for API: Gin
  • Package manager: go mod
  • DI: Based on service container
  • Layers: Controller->Service->Repository->Entity
  • Routes: Gin
  • Process controller results and convert them into JSON/XML according to request headers
  • Logger: logrus
  • Environment variables, config: Viper
  • ORM: GORM
  • Migrations: gorm-goose
  • Base CRUD service
  • Base CRUD repository
  • Base CRUD controller
  • Request validation (Gin)
  • Console commands: Cobra
  • Unit tests with overriding of services in DI (go test)
  • Code coverage by tests (go tool cover)
  • Logger integration with Sentry: logrus_sentry
  • Setup alerting for unhandled errors
  • Swagger
  • Docker compose

Folders structure

  • command/: Console commands.
  • controller/: Controllers for web requests processing.
  • db/: Migrations.
  • dic/: Dependency Injection Container.
  • doc/: Swagger documentation.
  • docker/: Docker containers description.
  • install/: Scripts for environment preparing.
  • logger/: Logger and client for Sentry.
  • model/: Business logic.
  • model/db/: DB connection.
  • model/entity/: GORM entities.
  • model/repository/: Repositories for access to storage.
  • model/service/: Business logic.
  • route/: Web requests routes.
  • test/: Unit tests.
  • vendor/: Packages used in application.
  • .env: Environment variables for current environment.
  • base.env: Base environment variables.

How to use (Docker)

docker-compose up --build

Check http://localhost:8080

How to use (without Docker)

Prepare environment for Go projects if you do not done it early

sudo apt update
sudo apt upgrade
# See last version here: https://golang.org/dl/
wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
sudo tar -xvf go1.12.5.linux-amd64.tar.gz
sudo mv go /usr/local
sudo mcedit /etc/profile

And add last line:

export PATH=$PATH:/usr/local/go/bin

Update environment variables:

source /etc/profile

Check Go version:

go version

Now create folder for Go projects:

mkdir ~/go
cd ~/go
touch init.sh
mcedit init.sh

Paste next code into this file:

#!/bin/bash

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Execute file:

chmod +x init.sh
source init.sh

Clone repo

git clone [email protected]:zubroide/go-api-boilerplate.git
cd go-api-boilerplate

Install necessary packages

./install/install.sh

Create and edit config

cp .env.example .env
mcedit .env

Download vendor packages

go mod download

Run migrations

Create database go-api-boilerplate.

And run migrations:

make migrate

Run application

make server

Or:

go run main.go server --port=8080

Check http://localhost:8080

Run tests

Run all tests:

go test ./... -v -coverpkg=./... -coverprofile=coverage.out
go tool cover -html=coverage.out

Run test for one package:

go test go-api-boilerplate/test/unit -v -coverpkg=./... -coverprofile=coverage.out

Run one test:

go test test/unit/user_service_test.go -v -coverpkg=./... -coverprofile=coverage.out

Using make:

make test

Generate Swagger documentation

Generate swagger.json:

make swagger

Documentation must be available at url http://localhost:8080/swagger/index.html

Requirements

  • Go 1.12+
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].