Skip to content

Commit feb6799

Browse files
authored
Initial commit
0 parents  commit feb6799

25 files changed

+919
-0
lines changed

.air.toml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "build"
4+
5+
[build]
6+
args_bin = []
7+
bin = "./build/app"
8+
cmd = "go build -gcflags='all=-N -l' -o ./build/app ."
9+
delay = 0
10+
exclude_dir = ["assets", "build", "vendor", "testdata"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
include_dir = []
16+
include_ext = ["go", "tpl", "tmpl", "html", "yaml"]
17+
include_file = []
18+
kill_delay = "0s"
19+
log = "build-errors.log"
20+
rerun = false
21+
rerun_delay = 500
22+
send_interrupt = false
23+
stop_on_error = true
24+
25+
[color]
26+
app = ""
27+
build = "yellow"
28+
main = "magenta"
29+
runner = "green"
30+
watcher = "cyan"
31+
32+
[log]
33+
main_only = true
34+
time = true
35+
36+
[misc]
37+
clean_on_exit = false
38+
39+
[screen]
40+
clear_on_rebuild = false
41+
keep_scroll = true

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
APP_ENV=dev
2+
APP_DEBUG=true

.github/workflows/post-install.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Post install
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
post_install:
10+
if: ${{ github.repository != 'ankorstore/yokai-http-template' }}
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
ref: ${{ github.head_ref }}
20+
21+
- name: Rename
22+
run: |
23+
make rename to=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')
24+
rm .github/workflows/post-install.yml
25+
26+
- name: Commit
27+
uses: stefanzweifel/git-auto-commit-action@v5
28+
with:
29+
commit_message: "Post installation operations"
30+
tagging_message: 'v0.1.0'
31+
push_options: --force

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
.idea
3+
/build/*

.golangci.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
run:
2+
timeout: 5m
3+
concurrency: 8
4+
5+
linters:
6+
enable:
7+
- asasalint
8+
- asciicheck
9+
- bidichk
10+
- bodyclose
11+
- containedctx
12+
- contextcheck
13+
- cyclop
14+
- decorder
15+
- dogsled
16+
- dupl
17+
- durationcheck
18+
- errcheck
19+
- errchkjson
20+
- errname
21+
- errorlint
22+
- exhaustive
23+
- forcetypeassert
24+
- gocognit
25+
- goconst
26+
- gocritic
27+
- gocyclo
28+
- godot
29+
- godox
30+
- gofmt
31+
- goheader
32+
- gomoddirectives
33+
- gomodguard
34+
- goprintffuncname
35+
- gosec
36+
- gosimple
37+
- govet
38+
- grouper
39+
- importas
40+
- ineffassign
41+
- interfacebloat
42+
- logrlint
43+
- maintidx
44+
- makezero
45+
- misspell
46+
- nestif
47+
- nilerr
48+
- nilnil
49+
- nlreturn
50+
- nolintlint
51+
- nosprintfhostport
52+
- prealloc
53+
- predeclared
54+
- promlinter
55+
- reassign
56+
- staticcheck
57+
- tenv
58+
- thelper
59+
- tparallel
60+
- typecheck
61+
- unconvert
62+
- unparam
63+
- unused
64+
- usestdlibvars
65+
- whitespace

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Multistage build
2+
FROM golang:1.22 as build
3+
ENV CGO_ENABLED=0
4+
ENV GOOS=linux
5+
ENV GOARCH=amd64
6+
7+
WORKDIR /src
8+
COPY . .
9+
RUN go mod download
10+
RUN go build -o /app
11+
12+
## Multistage deploy
13+
FROM gcr.io/distroless/base-debian10
14+
15+
WORKDIR /
16+
# Uncomment if you application provides HTTP templates
17+
# COPY --from=build /src/templates /templates
18+
COPY --from=build /src/configs /configs
19+
COPY --from=build /app /app
20+
21+
ENTRYPOINT ["/app"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Ankorstore
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
up:
2+
@if [ ! -f .env ]; then \
3+
cp .env.example .env; \
4+
fi
5+
docker compose up -d
6+
7+
down:
8+
docker compose down
9+
10+
fresh:
11+
@if [ ! -f .env ]; then \
12+
cp .env.example .env; \
13+
fi
14+
docker compose down --remove-orphans
15+
docker compose build --no-cache
16+
docker compose up -d --build -V
17+
18+
logs:
19+
docker compose logs -f
20+
21+
test:
22+
go test -v -race -cover -count=1 -failfast ./...
23+
24+
lint:
25+
golangci-lint run -v
26+
27+
rename:
28+
find . -type f ! -path "./.git/*" ! -path "./build/*" ! -path "./Makefile" -exec sed -i.bak -e "s|github.com/ankorstore/yokai-http-template|github.com/$(to)|g" {} \;
29+
find . -type f -name "*.bak" -delete

README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Yokai HTTP Template
2+
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4+
[![Go version](https://img.shields.io/badge/Go-1.22-blue)](https://go.dev/)
5+
6+
> HTTP application template based on the [Yokai](https://github.com/ankorstore/yokai) Go framework.
7+
8+
<!-- TOC -->
9+
* [Documentation](#documentation)
10+
* [Overview](#overview)
11+
* [Layout](#layout)
12+
* [Makefile](#makefile)
13+
* [Getting started](#getting-started)
14+
* [Installation](#installation)
15+
* [With GitHub](#with-github)
16+
* [With gonew](#with-gonew)
17+
* [Usage](#usage)
18+
<!-- TOC -->
19+
20+
## Documentation
21+
22+
For more information about the [Yokai](https://github.com/ankorstore/yokai) framework, you can check its [documentation](https://ankorstore.github.io/yokai).
23+
24+
## Overview
25+
26+
This template provides:
27+
28+
- a ready to extend [Yokai](https://github.com/ankorstore/yokai) application, with the [HTTP server](https://ankorstore.github.io/yokai/modules/fxhttpserver/) module installed
29+
- a ready to use [dev environment](docker-compose.yaml), based on [Air](https://github.com/cosmtrek/air) (for live reloading)
30+
- a ready to use [Dockerfile](Dockerfile) for production
31+
- some examples of [handler](internal/handler/example.go) and [test](internal/handler/example_test.go) to get started
32+
33+
### Layout
34+
35+
This template is following the [recommended project layout](https://go.dev/doc/modules/layout#server-project):
36+
37+
- `cmd/`: entry points
38+
- `configs/`: configuration files
39+
- `internal/`:
40+
- `handler/`: HTTP handler and test examples
41+
- `bootstrap.go`: bootstrap
42+
- `register.go`: dependencies registration
43+
- `router.go`: routing registration
44+
45+
### Makefile
46+
47+
This template provides a [Makefile](Makefile):
48+
49+
```
50+
make up # start the docker compose stack
51+
make down # stop the docker compose stack
52+
make logs # stream the docker compose stack logs
53+
make fresh # refresh the docker compose stack
54+
make test # run tests
55+
make lint # run linter
56+
```
57+
58+
## Getting started
59+
60+
### Installation
61+
62+
#### With GitHub
63+
64+
You can create your repository [using the GitHub template](https://github.com/new?template_name=yokai-http-template&template_owner=ankorstore).
65+
66+
It will automatically rename your project resources and push them, this operation can take a few minutes.
67+
68+
Once ready, after cloning and going into your repository, simply run:
69+
70+
```shell
71+
make fresh
72+
```
73+
74+
#### With gonew
75+
76+
You can install [gonew](https://go.dev/blog/gonew), and simply run:
77+
78+
```shell
79+
gonew github.com/ankorstore/yokai-http-template github.com/foo/bar
80+
cd bar
81+
make fresh
82+
```
83+
84+
### Usage
85+
86+
Once ready, the application will be available on:
87+
- [http://localhost:8080](http://localhost:8080) for the application HTTP server
88+
- [http://localhost:8081](http://localhost:8081) for the application core dashboard

cmd/root.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var rootCmd = &cobra.Command{
11+
Use: "app",
12+
CompletionOptions: cobra.CompletionOptions{
13+
DisableDefaultCmd: true,
14+
},
15+
}
16+
17+
func Execute() {
18+
if err := rootCmd.Execute(); err != nil {
19+
fmt.Printf("error: %v\n", err)
20+
os.Exit(1)
21+
}
22+
}

cmd/run.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmd
2+
3+
import (
4+
"github.com/ankorstore/yokai-http-template/internal"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func init() {
9+
rootCmd.AddCommand(runCmd)
10+
}
11+
12+
var runCmd = &cobra.Command{
13+
Use: "run",
14+
Short: "Run application",
15+
Run: func(cmd *cobra.Command, args []string) {
16+
internal.Run(cmd.Context())
17+
},
18+
}

configs/config.dev.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
app:
2+
debug: true
3+
modules:
4+
log:
5+
level: debug
6+
output: console

configs/config.prod.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
app:
2+
debug: false
3+
modules:
4+
core:
5+
server:
6+
metrics:
7+
collect:
8+
enabled: false
9+
debug:
10+
pprof:
11+
expose: false
12+
stats:
13+
expose: false

configs/config.test.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
app:
2+
debug: true
3+
modules:
4+
log:
5+
level: debug
6+
output: test
7+
trace:
8+
processor:
9+
type: test

0 commit comments

Comments
 (0)