Focused on PostgreSQL database (master branch)
- Database using PostgreSQL: master branch
- Database using MySQL: checkout branch mysql
- Support for gRPC (database using PostgreSQL): checkout branch grpc-postgresql
- Support for gRPC (database using MySQL): checkout branch grpc-mysql
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.
-
Clone project.
$ git clone https://github.com/geshtng/go-base-backend
-
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.
- Create a new database. Example database name:
-
Change config.
Make a new file named
config.yamlinside the folder/config.
Useconfig.yaml.exampleto 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
$ make runYou can find API list on file routes/routes.go
I have set up an example of an API that uses authentication:
GET localhost:8080/profilesImport files go-base-backend.postman_collection.json to your postman
- Gin
- Gorm
- Copier
- Golang-jwt
- Viper
- Testify
- Go-Sqlmock
- Other libraries listed in
go.mod