Skip to content

Commit bb9a356

Browse files
author
Vic Shóstak
committed
Update README
1 parent a505ac9 commit bb9a356

File tree

2 files changed

+90
-56
lines changed

2 files changed

+90
-56
lines changed

.dockerignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
.dockerignore
33
.editorconfig
44
.gitignore
5+
.env.example
56
Dockerfile
67
Makefile
78
LICENSE
8-
*.md
9+
**/*.md
10+
**/*_test.go
911

1012
# Folders
1113
.git/
1214
.github/
13-
build/
14-
**/*_test.go
15+
build/

README.md

Lines changed: 86 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,115 @@
11
# net/http backend template for [Create Go App CLI](https://github.com/create-go-app/cli)
22

3-
<img src="https://img.shields.io/badge/Go-1.11+-00ADD8?style=for-the-badge&logo=go" alt="go version" />&nbsp;<a href="https://gocover.io/github.com/create-go-app/net_http-go-template/pkg/apiserver" target="_blank"><img src="https://img.shields.io/badge/Go_Cover-49%25-success?style=for-the-badge&logo=none" alt="go cover" /></a>&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/net_http-go-template" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a>&nbsp;<img src="https://img.shields.io/badge/license-mit-red?style=for-the-badge&logo=none" alt="license" />
3+
<img src="https://img.shields.io/badge/Go-1.16+-00ADD8?style=for-the-badge&logo=go" alt="go version" />&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/net_http-go-template" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a>&nbsp;<img src="https://img.shields.io/badge/license-mit-red?style=for-the-badge&logo=none" alt="license" />
44

55
Package `net` provides a portable interface for network I/O, including TCP/IP, UDP, domain name resolution, and Unix domain sockets. Although the package provides access to low-level networking primitives.
66

77
Package [`net/http`](https://golang.org/pkg/net/http/) provides HTTP client and server implementations.
88

99
## ⚡️ Quick start
1010

11-
1. Create a new project:
11+
1. Create a new project with Fiber:
1212

1313
```bash
1414
cgapp create
15+
16+
# Choose a backend framework:
17+
# > net/http
18+
# Fiber
1519
```
1620

17-
2. Run project by this command:
21+
2. Run Docker container with database (_by default, for PostgreSQL_):
1822

1923
```bash
20-
make run
24+
make docker.postgres
2125
```
2226

23-
## ✅ Used packages
27+
3. Apply migrations:
2428

25-
- [gorilla/mux](https://github.com/gorilla/mux) `v1.7.4`
26-
- [go-yaml/yaml](https://github.com/go-yaml/yaml) `v2.3.0`
29+
```bash
30+
make migration.up user=<db_user> pass=<db_pass> host=<db_host> table=<db_table>
31+
```
2732

28-
## 🗄 Template structure
33+
4. Rename `.env.example` to `.env` and fill it with your environment values.
34+
35+
5. Run project by this command:
2936

3037
```bash
31-
.
32-
├── .dockerignore
33-
├── .editorconfig
34-
├── .gitignore
35-
├── Dockerfile
36-
├── Makefile
37-
├── go.mod
38-
├── go.sum
39-
├── main.go
40-
├── configs
41-
│ └── apiserver.yml
42-
├── static
43-
│ └── index.html
44-
└── pkg
45-
└── apiserver
46-
├── config.go
47-
├── config_test.go
48-
├── error_checker.go
49-
├── error_checker_test.go
50-
├── new_server.go
51-
├── new_server_test.go
52-
├── routes.go
53-
├── utils.go
54-
└── utils_test.go
55-
56-
4 directories, 17 files
38+
make run
5739
```
5840

41+
6. Go to API Docs page (Swagger): [localhost:5000/swagger/index.html](http://localhost:5000/swagger/index.html).
42+
43+
## 📦 Used packages
44+
45+
| Name | Version | Type |
46+
| --------------------------------------------------------------------- | --------- | ---------- |
47+
| [net/http](https://golang.org/pkg/net/http/) | `v1.16.0` | core |
48+
| [auth0/go-jwt-middleware](https://github.com/auth0/go-jwt-middleware) | `v1.0.0` | middleware |
49+
| [swaggo/http-swagger](https://github.com/swaggo/http-swagger) | `v1.0.0` | middleware |
50+
| [stretchr/testify](https://github.com/stretchr/testify) | `v1.7.0` | tests |
51+
| [dgrijalva/jwt-go](https://github.com/dgrijalva/jwt-go) | `v3.2.0` | auth |
52+
| [joho/godotenv](https://github.com/joho/godotenv) | `v1.3.0` | config |
53+
| [jmoiron/sqlx](https://github.com/jmoiron/sqlx) | `v1.3.1` | database |
54+
| [jackc/pgx](https://github.com/jackc/pgx) | `v4.10.1` | database |
55+
| [swaggo/swag](https://github.com/swaggo/swag) | `v1.7.0` | utils |
56+
| [google/uuid](https://github.com/google/uuid) | `v1.2.0` | utils |
57+
| [go-playground/validator](https://github.com/go-playground/validator) | `v10.4.1` | utils |
58+
59+
## 🗄 Template structure
60+
61+
### ./app
62+
63+
**Folder with business logic only**. This directory doesn't care about _what database driver you're using_ or _which caching solution your choose_ or any third-party things.
64+
65+
- `./app/controllers` folder for functional controllers (used in routes)
66+
- `./app/models` folder for describe business models and methods of your project
67+
- `./app/queries` folder for describe queries for models of your project
68+
- `./app/validators` folder for describe validators for models fields
69+
70+
### ./docs
71+
72+
**Folder with API Documentation**. This directory contains config files for auto-generated API Docs by Swagger.
73+
74+
### ./pkg
75+
76+
**Folder with project-specific functionality**. This directory contains all the project-specific code tailored only for your business use case, like _configs_, _middleware_, _routes_ or _utils_.
77+
78+
- `./pkg/configs` folder for configuration functions
79+
- `./pkg/middleware` folder for add middleware (Fiber built-in and yours)
80+
- `./pkg/routes` folder for describe routes of your project
81+
- `./pkg/utils` folder with utility functions (server starter, error checker, etc)
82+
83+
### ./platform
84+
85+
**Folder with platform-level logic**. This directory contains all the platform-level logic that will build up the actual project, like _setting up the database_ or _cache server instance_ and _storing migrations_.
86+
87+
- `./platform/database` folder with database setup functions (by default, PostgreSQL)
88+
- `./platform/migrations` folder with migration files (used with [golang-migrate/migrate](https://github.com/golang-migrate/migrate) tool)
89+
5990
## ⚙️ Configuration
6091

61-
```yaml
62-
# ./configs/apiserver.yml
63-
64-
# Server config
65-
server:
66-
host: 0.0.0.0
67-
port: 5000
68-
69-
# Database config
70-
database:
71-
host: 127.0.0.1
72-
port: 5432
73-
username: postgres
74-
password: 1234
75-
76-
# Static files config
77-
static:
78-
prefix: /
79-
path: ./static
92+
```ini
93+
# .env
94+
95+
# Server settings:
96+
SERVER_URL="0.0.0.0:5000"
97+
SERVER_EMAIL="no-reply@example.com"
98+
SERVER_EMAIL_PASSWORD="secret"
99+
100+
# JWT settings:
101+
JWT_SECRET_KEY="secret"
102+
JWT_REFRESH_KEY="refresh"
103+
104+
# Database settings:
105+
DB_SERVER_URL="host=localhost port=5432 user=postgres password=password dbname=postgres sslmode=disable"
106+
DB_MAX_CONNECTIONS=100
107+
DB_MAX_IDLE_CONNECTIONS=10
108+
DB_MAX_LIFETIME_CONNECTIONS=2
109+
110+
# SMTP severs settings:
111+
SMTP_SERVER="smtp.example.com"
112+
SMTP_PORT=25
80113
```
81114

82115
## ⚠️ License

0 commit comments

Comments
 (0)