Skip to content

Commit d29df0b

Browse files
committed
Initial commit
1 parent 86c80f9 commit d29df0b

File tree

18 files changed

+385
-3
lines changed

18 files changed

+385
-3
lines changed

.dockerignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Files
2+
.dockerignore
3+
.editorconfig
4+
.gitignore
5+
.env.*
6+
Dockerfile
7+
Makefile
8+
LICENSE
9+
**/*.md
10+
**/*_test.go
11+
*.out
12+
*.http
13+
14+
# Folders
15+
.vscode/
16+
.idea/
17+
.git/
18+
.github/
19+
build/

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{go.mod,go.sum,*.go}]
11+
indent_style = tab
12+
indent_size = 4
13+
14+
[{Makefile,Dockerfile,*.yml,*.yaml}]
15+
indent_style = tab
16+
indent_size = 2

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Stage status to start server:
2+
# - "dev", for start server without graceful shutdown
3+
# - "prod", for start server with graceful shutdown
4+
STAGE_STATUS="dev"
5+
6+
# Server settings:
7+
SERVER_HOST="0.0.0.0"
8+
SERVER_PORT=5000
9+
SERVER_READ_TIMEOUT=5
10+
SERVER_WRITE_TIMEOUT=10
11+
SERVER_IDLE_TIMEOUT=120

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
go.sum merge=union

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# macOS
2+
**/.DS_Store
3+
4+
# IDE
5+
.vscode/
6+
.idea/
7+
8+
# Dev build
9+
build/
10+
tmp/
11+
12+
# Test
13+
*.out
14+
*.http
15+
16+
# Environment variables
17+
.env

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM golang:1.17-alpine AS builder
2+
3+
LABEL maintainer="Vic Shóstak <[email protected]> (https://shostak.dev/)"
4+
5+
# Move to working directory (/build).
6+
WORKDIR /build
7+
8+
# Copy and download dependency using go mod.
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
12+
# Copy the code into the container.
13+
COPY . .
14+
15+
# Set necessary environment variables needed for our image and build the API server.
16+
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
17+
RUN go build -ldflags="-s -w" -o apiserver .
18+
19+
FROM scratch
20+
21+
# Copy binary and config files from /build to root folder of scratch container.
22+
COPY --from=builder ["/build/apiserver", "/build/.env", "/"]
23+
24+
# Command to run when starting the container.
25+
ENTRYPOINT ["/apiserver"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2021 Vic Shóstak and Create Go App Contributors
189+
Copyright 2022 Vic Shóstak and Create Go App Contributors
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.PHONY: clean critic security lint test build run
2+
3+
APP_NAME = apiserver
4+
BUILD_DIR = $(PWD)/build
5+
6+
clean:
7+
rm -rf ./build
8+
9+
critic:
10+
gocritic check -enableAll ./...
11+
12+
security:
13+
gosec ./...
14+
15+
lint:
16+
golangci-lint run ./...
17+
18+
test: clean critic security lint
19+
go test -v -timeout 30s -coverprofile=cover.out -cover ./...
20+
go tool cover -func=cover.out
21+
22+
build: test
23+
CGO_ENABLED=0 go build -ldflags="-w -s" -o $(BUILD_DIR)/$(APP_NAME) main.go
24+
25+
run: build
26+
$(BUILD_DIR)/$(APP_NAME)
27+
28+
docker.run: docker.network docker.chi
29+
30+
docker.network:
31+
docker network inspect dev-network >/dev/null 2>&1 || \
32+
docker network create -d bridge dev-network
33+
34+
docker.chi.build:
35+
docker build -t chi .
36+
37+
docker.chi: docker.chi.build
38+
docker run --rm -d \
39+
--name cgapp-chi \
40+
--network dev-network \
41+
-p 5000:5000 \
42+
chi
43+
44+
docker.stop: docker.stop.chi
45+
46+
docker.stop.chi:
47+
docker stop cgapp-chi

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
# chi-go-template
2-
📝 [WIP] Chi backend template for Create Go App CLI.
1+
# go-chi backend template for [Create Go App CLI](https://github.com/create-go-app/cli)
2+
3+
<img src="https://img.shields.io/badge/Go-1.17+-00ADD8?style=for-the-badge&logo=go" alt="go version" />
4+
&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/fiber-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>
5+
&nbsp;<img src="https://img.shields.io/badge/license-Apache_2.0-red?style=for-the-badge&logo=none" alt="license" />
6+
7+
[chi](https://go-chi.io/#/) iis a lightweight, idiomatic and composable router for building Go HTTP services.
8+
9+
## ⚡️ Quick start
10+
11+
1. Create a new project with Fiber:
12+
13+
```bash
14+
cgapp create
15+
16+
# Choose a backend framework:
17+
# net/http
18+
# fiber
19+
# > go-chi
20+
```
21+
22+
2. Rename `.env.example` to `.env` and fill it with your environment values.
23+
3. Install [Docker](https://www.docker.com/get-started) and the following useful Go tools to your system:
24+
25+
- [golang-migrate/migrate](https://github.com/golang-migrate/migrate#cli-usage) for apply migrations
26+
- [github.com/securego/gosec](https://github.com/securego/gosec) for checking Go security issues
27+
- [github.com/go-critic/go-critic](https://github.com/go-critic/go-critic) for checking Go the best practice issues
28+
- [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) for checking Go linter issues
29+
30+
4. Run project by this command:
31+
32+
```bash
33+
make docker.run
34+
```
35+
36+
## 📦 Used packages
37+
38+
| Name | Version | Type |
39+
|-----------------------------------------------------------------------| -------- | ---------- |
40+
| [go-chi/chi](https://github.com/go-chi/chi) | `v5.0.7` | core |
41+
| [joho/godotenv](https://github.com/joho/godotenv) | `v1.4.0` | config |
42+
43+
## ⚙️ Configuration
44+
45+
```ini
46+
# .env
47+
48+
# Stage status to start server:
49+
# - "dev", for start server without graceful shutdown
50+
# - "prod", for start server with graceful shutdown
51+
STAGE_STATUS="dev"
52+
53+
# Server settings:
54+
SERVER_HOST="0.0.0.0"
55+
SERVER_PORT=5000
56+
SERVER_READ_TIMEOUT=5
57+
SERVER_WRITE_TIMEOUT=10
58+
SERVER_IDLE_TIMEOUT=120
59+
```
60+
61+
## ⚠️ License
62+
63+
Apache 2.0 &copy; [Vic Shóstak](https://shostak.dev/) & [True web artisans](https://1wa.co/).

api_test.http

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GET http://localhost:5000/hc/status
2+
3+
###

0 commit comments

Comments
 (0)