Coder Social home page Coder Social logo

chrisloarryn / echo-rest-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dzungtran/echo-rest-api

0.0 0.0 0.0 941 KB

A Golang restful API boilerplate based on Echo framework v4. Includes tools for module generation, db migration, authorization, modular, authentication and more.

License: MIT License

Shell 0.16% Go 90.65% Makefile 0.65% Smarty 4.02% Dockerfile 0.25% Open Policy Agent 2.97% CUE 1.29%

echo-rest-api's Introduction

Build Status codecov License: MIT Go Reference GoReportCard Badge Total alerts

Echo REST API boilerplate

A Golang restful API boilerplate based on Echo framework v4. Includes tools for module generation, db migration, authorization, authentication and more. Any feedback and pull requests are welcome and highly appreciated. Feel free to open issues just for comments and discussions.

HOW TO USE THIS TEMPLATE

DO NOT FORK this is meant to be used from Use this template feature.

  1. Click on Use this template
  2. Give a name to your project
    (e.g. my_awesome_project recommendation is to use all lowercase and underscores separation for repo names.)
  3. Wait until the first run of CI finishes
    (Github Actions will process the template and commit to your new repo)
  4. Then clone your new project and happy coding!

NOTE: WAIT until first CI run on github actions before cloning your new project.

Features

  • User Auth functionality (Signup, Login, Forgot Password, Reset Password, 2FA) using Firebase Auth
  • REST API using labstack/echo.
  • DB Migration using golang-migrate/migrate.
  • Modular structure.
  • Configs via environmental variables.
  • Unit tests.
  • Dependency injection using uber-go/dig.
  • Role based access control using Open Policy Agent.
  • Module generation, quickly create model, usecase, api handler.
  • CLI support. try: go run ./tools/mod/ gen using spf13/cobra.
  • Generate API docs using swaggo. Try: make docs.

Running the project

  • Make sure you have docker installed.
  • Copy .env.example to .env.docker
  • Run docker compose up -d.
  • Go to localhost:8088 to verify if the API server works.

Swagger Docs

To create swagger api documentation you just have to run make docs.
after the command executed successfully, run the app and open http://localhost:8088/docs/index.html to see swagger documentation page.

Environment variables

By default, when you run application with make run-api command, it will look at $HOME/.env for exporting environment variabels. Setting your config as Environment Variables is recommended as by 12-Factor App.

Variables Defined in the project
Name Type Description Example value
DATABASE_URL string Data source URL for main DB postgres://world:hello@postgres/echo_rest_api
PORT integer Http port (accepts also port number only for heroku compability) 8088
AUTO_MIGRATE boolean Enable run migration every time the application starts true
ENV string Environment name development
REDIS_URL string Optional redis://redis:6379
AUTH_PROVIDER string Optional firebase_auth
FIREBASE_CREDENTIALS json firebase json admin key {firebase_admin_key}
FIREBASE_AUTH_CREDENTIALS json filebase json auth key {firebase_auth_key}
KRATOS_API_ENDPOINT string [DEPRECATED] Public endpoint of Kratos http://kratos:4433/
KRATOS_WEBHOOK_API_KEY string [DEPRECATED] Api key for Kratos integration very-very-very-secure-api-key

Commands

Command Description
make run-api Start REST API application
make build-api Build application binary
make setup Run commands to setup development env
make run-db Run DB docker container on local
go run ./tools/mod/ gen Generate module component codes. e.g: go run ./tools/mod/ gen -n Booking
make migration-create [migration_name] Create migration files. migration_name should be snake case
make git-hooks Setup git hooks
make routes Generate routes file for authorization
make docs Generate API docs

Folder Structure

.
├── 3rd-parties         # Thirdparty configs
├── cmd
│   └── api             # Main package of API service
├── config              # Application configs struct
│   ...        
├── docs                # Contains documentation and PlantUML for charts and diagrams
├── domains
├── infrastructure
├── migrations
│   └── sql             # Migration files
├── modules
│   ├── core            # Core module, includes apis: users, orgs
│   ├── projects        # Demo module generation
│   └── shared          # To store common usecases and domains which shared between modules
├── out                 # Output folder of PlantUML
├── pkg
│   ├── authz           # Contains Rego rule files for RBAC
│   ├── constants
│   ├── cue             # Contains cue files for data validation
│   ...
│   └── utils           # Contains helper functions
├── tests
└── tools
   ├── modtool         # Module generation
   ├── routes          # Generate routes file for Authorization
   └── scripts         # Some helpful bash commands

Open Source Refs

Contributing

Please open issues if you want the template to add some features that is not in todos.

Create a PR with relevant information if you want to contribute in this template.

TODOs

  • Update docker compose for ory/kratos.
  • Update README.md.
  • Update API docs.
  • Write more tests.

echo-rest-api's People

Contributors

dzungtran avatar dependabot[bot] avatar alirzasahb avatar javadbat 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.