Skip to content

Commit a3e6e66

Browse files
author
Vic Shóstak
committed
New structure
1 parent 7ce0ba6 commit a3e6e66

36 files changed

+1208
-549
lines changed

.env.example

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Server settings:
2+
SERVER_URL="0.0.0.0:5000"
3+
SERVER_EMAIL="[email protected]"
4+
SERVER_EMAIL_PASSWORD="secret"
5+
6+
# JWT settings:
7+
JWT_SECRET_KEY="secret"
8+
JWT_REFRESH_KEY="refresh"
9+
10+
# Database settings:
11+
DB_SERVER_URL="host=localhost port=5432 user=postgres password=password dbname=postgres sslmode=disable"
12+
DB_MAX_CONNECTIONS=100
13+
DB_MAX_IDLE_CONNECTIONS=10
14+
DB_MAX_LIFETIME_CONNECTIONS=2
15+
16+
# SMTP severs settings:
17+
SMTP_SERVER="smtp.example.com"
18+
SMTP_PORT=25

.gitignore

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
# macOS
22
**/.DS_Store
33

4-
# Binaries for programs and plugins
5-
**/*.exe
6-
**/*.exe~
7-
**/*.dll
8-
**/*.so
9-
**/*.dylib
4+
# Dev build
5+
build/
6+
tmp/
107

11-
# Test binary, built with `go test -c`
12-
**/*.test
8+
# Test
9+
*.out
10+
*.test
1311

14-
# Dev Build
15-
**/app/
16-
**/build/
17-
18-
# Taskfile
19-
.task/
12+
# Environment variables
13+
.env

Dockerfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14-alpine AS builder
1+
FROM golang:1.16-alpine AS builder
22

33
# Move to working directory (/build).
44
WORKDIR /build
@@ -10,18 +10,18 @@ RUN go mod download
1010
# Copy the code into the container.
1111
COPY . .
1212

13-
# Set necessary environment variables needed for our image and build the API server.
14-
ENV GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64
15-
RUN go build -ldflags="-w -s" -o apiserver .
13+
# Set necessary environmet variables needed for our image and build the API server.
14+
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
15+
RUN go build -ldflags="-s -w" -o apiserver .
1616

1717
FROM scratch
1818

1919
# Copy binary and config files from /build to root folder of scratch container.
20-
COPY --from=builder ["/build/apiserver", "/build/configs/apiserver.yml", "/"]
20+
COPY --from=builder ["/build/apiserver", "/build/.env", "/"]
2121

2222
# Export necessary port.
2323
EXPOSE 5000
2424

2525
# Command to run when starting the container.
26-
ENV CONFIG_PATH=/apiserver.yml
27-
ENTRYPOINT ["/apiserver"]
26+
ENV CONFIG_PATH=/.env
27+
ENTRYPOINT ["/apiserver"]

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Vic Shóstak <[email protected]> (https://1wa.co)
3+
Copyright (c) 2021 Vic Shóstak <[email protected]> (https://1wa.co)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

+44-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
.PHONY: clean test security build run
22

3-
BUILD_DIR = $(PWD)/build
43
APP_NAME = apiserver
4+
BUILD_DIR = $(PWD)/build
5+
MIGRATIONS_FOLDER = $(PWD)/platform/migrations
6+
DATABASE_URL = postgres://$(user):$(pass)@$(host)/$(table)?sslmode=disable
57

68
clean:
79
rm -rf ./build
810

9-
test:
10-
go test -cover ./...
11-
1211
security:
1312
gosec -quiet ./...
1413

15-
build: security test
14+
test: security
15+
go test -cover ./...
16+
17+
build: clean test
1618
CGO_ENABLED=0 go build -ldflags="-w -s" -o $(BUILD_DIR)/$(APP_NAME) main.go
1719

18-
run: clean build
20+
run: swag.init build
1921
$(BUILD_DIR)/$(APP_NAME)
22+
23+
migrate.up:
24+
migrate -path $(MIGRATIONS_FOLDER) -database "$(DATABASE_URL)" up
25+
26+
migrate.down:
27+
migrate -path $(MIGRATIONS_FOLDER) -database "$(DATABASE_URL)" down
28+
29+
migrate.force:
30+
migrate -path $(MIGRATIONS_FOLDER) -database "$(DATABASE_URL)" force $(version)
31+
32+
docker.build:
33+
docker build -t fiber-go-template .
34+
35+
docker.run: docker.net_http docker.postgres
36+
37+
docker.stop:
38+
docker stop dev-net_http dev-postgres
39+
40+
docker.net_http:
41+
docker run --rm -d \
42+
--name dev-net_http \
43+
--network dev-network \
44+
-p 5000:5000 \
45+
net_http-go-template
46+
47+
docker.postgres:
48+
docker run --rm -d \
49+
--name dev-postgres \
50+
--network dev-network \
51+
-e POSTGRES_PASSWORD=password \
52+
-v ${HOME}/dev-postgres/data/:/var/lib/postgresql/data \
53+
-p 5432:5432 \
54+
postgres
55+
56+
swag.init:
57+
swag init

app/BUSINESS_LOGIC.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# ./app
2+
3+
**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.
4+
5+
- `./app/controllers` folder for functional controllers (used in routes)
6+
- `./app/models` folder for describe business models of your project
7+
- `./app/queries` folder for describe queries for models of your project
8+
- `./app/validators` folder for describe validators for models fields

0 commit comments

Comments
 (0)