Skip to content

geshtng/go-base-backend

Repository files navigation

Focused on PostgreSQL database (master branch)

go-base-backend

Release List

  1. Database using PostgreSQL: master branch
  2. Database using MySQL: checkout branch mysql
  3. Support for gRPC (database using PostgreSQL): checkout branch grpc-postgresql
  4. Support for gRPC (database using MySQL): checkout branch grpc-mysql

Description

Example implementation go backend (clean) architecture. It is very easy to configure.

This project has 4 domain layers:

  • Model
    This layer will save models that were used in the other domains. Can be accessed from any other layer and other domains.
  • Handler
    This layer will do the job as the presenter of the application.
  • Service
    This layer will do the job as a controller and handle the business logic.
  • Repository
    This layer is the one that stores the database handler. Any operation on database like querying, inserting, updating, and deleting, will be done on this layer.

Setup

  1. Clone project.

    $ git clone https://github.com/geshtng/go-base-backend
  2. Init Database.

    • Create a new database. Example database name: go_base_backend.
    • After you run the server, it will automatically create tables and relations in the database go_base_backend.
  3. Change config.

    Make a new file named config.yaml inside the folder /config.
    Use config.yaml.example to see the example or see the config sample below.

    app: name: go-base-backend server: host: localhost port: 8080 database: db_host: localhost db_port: 5432 db_name: go_base_backend db_username: postgres db_password: postgres db_postgres_ssl_mode: disable jwt: expired: 60 issuer: go-base-backend secret: sKk6E5gpVD

Run the Project

$ make run

API List

You can find API list on file routes/routes.go

Example API with Authentication

I have set up an example of an API that uses authentication:

GET localhost:8080/profiles

Postman Collection

Import files go-base-backend.postman_collection.json to your postman

Framework and Library