Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ralxyz/go-svc-tpl
Golang back-end service template, get started with back-end projects quickly
https://github.com/ralxyz/go-svc-tpl
backend
Last synced: about 1 month ago
JSON representation
Golang back-end service template, get started with back-end projects quickly
- Host: GitHub
- URL: https://github.com/ralxyz/go-svc-tpl
- Owner: RalXYZ
- License: unlicense
- Created: 2022-01-27T04:09:25.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T03:11:18.000Z (3 months ago)
- Last Synced: 2024-12-15T17:12:01.436Z (about 1 month ago)
- Topics: backend
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 19
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Golang Service Template
Golang back-end service template. Using this template, you can get started with back-end projects quickly.
| Web Framework | ORM | Database Driver | Configuration Manager | Log Manager | API Documentation |
|:----------------:|:------------:|:--------------------:|:---------------------:|:---------------:|:-------------------:|
| labstack/echo/v4 | gorm.io/gorm | gorm.io/driver/mysql | spf13/viper | sirupsen/logrus | swaggo/echo-swagger |## Configuration
1. Create database and user in MySQL, and grant privileges to user.
```sql
CREATE DATABASE buz;
CREATE USER 'foo'@'localhost' IDENTIFIED BY 'bar';
GRANT ALL PRIVILEGES ON buz.* TO 'foo'@'localhost';
```2. Create a file named `conf.yaml` in the project's root directory.
```yaml
sql:
username: foo
password: bar
db_name: buz
```3. To generate API doc, you need to execute the following commands:
```shell
go install github.com/swaggo/swag/cmd/[email protected] # download swag, a doc generator
swag init # docs will be written into `docs/` directory
```4. Compile and run this project. You will find API doc in `http://localhost:1323/api/doc/index.html` on default.
5. Change the go module name of this project to whatever you like.## Usage
1. To create tables, add structs in `model/`. `model/foo.go` is an example of such struct. Then, add the struct to `DB.AutoMigrate` in `model/init.go`.
2. Add business logics in `app/controller/`, then add router in `app/routers.go`.
3. Write API doc alongside with the controller function. `app/controller/foo.go` is an example.