generated from ankorstore/yokai-http-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit feb6799
Showing
25 changed files
with
919 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "build" | ||
|
||
[build] | ||
args_bin = [] | ||
bin = "./build/app" | ||
cmd = "go build -gcflags='all=-N -l' -o ./build/app ." | ||
delay = 0 | ||
exclude_dir = ["assets", "build", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html", "yaml"] | ||
include_file = [] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
rerun = false | ||
rerun_delay = 500 | ||
send_interrupt = false | ||
stop_on_error = true | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
main_only = true | ||
time = true | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[screen] | ||
clear_on_rebuild = false | ||
keep_scroll = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
APP_ENV=dev | ||
APP_DEBUG=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Post install | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
post_install: | ||
if: ${{ github.repository != 'ankorstore/yokai-http-template' }} | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Rename | ||
run: | | ||
make rename to=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]') | ||
rm .github/workflows/post-install.yml | ||
- name: Commit | ||
uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: "Post installation operations" | ||
tagging_message: 'v0.1.0' | ||
push_options: --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.env | ||
.idea | ||
/build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
run: | ||
timeout: 5m | ||
concurrency: 8 | ||
|
||
linters: | ||
enable: | ||
- asasalint | ||
- asciicheck | ||
- bidichk | ||
- bodyclose | ||
- containedctx | ||
- contextcheck | ||
- cyclop | ||
- decorder | ||
- dogsled | ||
- dupl | ||
- durationcheck | ||
- errcheck | ||
- errchkjson | ||
- errname | ||
- errorlint | ||
- exhaustive | ||
- forcetypeassert | ||
- gocognit | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- godot | ||
- godox | ||
- gofmt | ||
- goheader | ||
- gomoddirectives | ||
- gomodguard | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- govet | ||
- grouper | ||
- importas | ||
- ineffassign | ||
- interfacebloat | ||
- logrlint | ||
- maintidx | ||
- makezero | ||
- misspell | ||
- nestif | ||
- nilerr | ||
- nilnil | ||
- nlreturn | ||
- nolintlint | ||
- nosprintfhostport | ||
- prealloc | ||
- predeclared | ||
- promlinter | ||
- reassign | ||
- staticcheck | ||
- tenv | ||
- thelper | ||
- tparallel | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- usestdlibvars | ||
- whitespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Multistage build | ||
FROM golang:1.22 as build | ||
ENV CGO_ENABLED=0 | ||
ENV GOOS=linux | ||
ENV GOARCH=amd64 | ||
|
||
WORKDIR /src | ||
COPY . . | ||
RUN go mod download | ||
RUN go build -o /app | ||
|
||
## Multistage deploy | ||
FROM gcr.io/distroless/base-debian10 | ||
|
||
WORKDIR / | ||
# Uncomment if you application provides HTTP templates | ||
# COPY --from=build /src/templates /templates | ||
COPY --from=build /src/configs /configs | ||
COPY --from=build /app /app | ||
|
||
ENTRYPOINT ["/app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Ankorstore | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
up: | ||
@if [ ! -f .env ]; then \ | ||
cp .env.example .env; \ | ||
fi | ||
docker compose up -d | ||
|
||
down: | ||
docker compose down | ||
|
||
fresh: | ||
@if [ ! -f .env ]; then \ | ||
cp .env.example .env; \ | ||
fi | ||
docker compose down --remove-orphans | ||
docker compose build --no-cache | ||
docker compose up -d --build -V | ||
|
||
logs: | ||
docker compose logs -f | ||
|
||
test: | ||
go test -v -race -cover -count=1 -failfast ./... | ||
|
||
lint: | ||
golangci-lint run -v | ||
|
||
rename: | ||
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" {} \; | ||
find . -type f -name "*.bak" -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Yokai HTTP Template | ||
|
||
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
[![Go version](https://img.shields.io/badge/Go-1.22-blue)](https://go.dev/) | ||
|
||
> HTTP application template based on the [Yokai](https://github.com/ankorstore/yokai) Go framework. | ||
<!-- TOC --> | ||
* [Documentation](#documentation) | ||
* [Overview](#overview) | ||
* [Layout](#layout) | ||
* [Makefile](#makefile) | ||
* [Getting started](#getting-started) | ||
* [Installation](#installation) | ||
* [With GitHub](#with-github) | ||
* [With gonew](#with-gonew) | ||
* [Usage](#usage) | ||
<!-- TOC --> | ||
|
||
## Documentation | ||
|
||
For more information about the [Yokai](https://github.com/ankorstore/yokai) framework, you can check its [documentation](https://ankorstore.github.io/yokai). | ||
|
||
## Overview | ||
|
||
This template provides: | ||
|
||
- a ready to extend [Yokai](https://github.com/ankorstore/yokai) application, with the [HTTP server](https://ankorstore.github.io/yokai/modules/fxhttpserver/) module installed | ||
- a ready to use [dev environment](docker-compose.yaml), based on [Air](https://github.com/cosmtrek/air) (for live reloading) | ||
- a ready to use [Dockerfile](Dockerfile) for production | ||
- some examples of [handler](internal/handler/example.go) and [test](internal/handler/example_test.go) to get started | ||
|
||
### Layout | ||
|
||
This template is following the [recommended project layout](https://go.dev/doc/modules/layout#server-project): | ||
|
||
- `cmd/`: entry points | ||
- `configs/`: configuration files | ||
- `internal/`: | ||
- `handler/`: HTTP handler and test examples | ||
- `bootstrap.go`: bootstrap | ||
- `register.go`: dependencies registration | ||
- `router.go`: routing registration | ||
|
||
### Makefile | ||
|
||
This template provides a [Makefile](Makefile): | ||
|
||
``` | ||
make up # start the docker compose stack | ||
make down # stop the docker compose stack | ||
make logs # stream the docker compose stack logs | ||
make fresh # refresh the docker compose stack | ||
make test # run tests | ||
make lint # run linter | ||
``` | ||
|
||
## Getting started | ||
|
||
### Installation | ||
|
||
#### With GitHub | ||
|
||
You can create your repository [using the GitHub template](https://github.com/new?template_name=yokai-http-template&template_owner=ankorstore). | ||
|
||
It will automatically rename your project resources and push them, this operation can take a few minutes. | ||
|
||
Once ready, after cloning and going into your repository, simply run: | ||
|
||
```shell | ||
make fresh | ||
``` | ||
|
||
#### With gonew | ||
|
||
You can install [gonew](https://go.dev/blog/gonew), and simply run: | ||
|
||
```shell | ||
gonew github.com/ankorstore/yokai-http-template github.com/foo/bar | ||
cd bar | ||
make fresh | ||
``` | ||
|
||
### Usage | ||
|
||
Once ready, the application will be available on: | ||
- [http://localhost:8080](http://localhost:8080) for the application HTTP server | ||
- [http://localhost:8081](http://localhost:8081) for the application core dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "app", | ||
CompletionOptions: cobra.CompletionOptions{ | ||
DisableDefaultCmd: true, | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Printf("error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/ankorstore/yokai-http-template/internal" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(runCmd) | ||
} | ||
|
||
var runCmd = &cobra.Command{ | ||
Use: "run", | ||
Short: "Run application", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
internal.Run(cmd.Context()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
app: | ||
debug: true | ||
modules: | ||
log: | ||
level: debug | ||
output: console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
app: | ||
debug: false | ||
modules: | ||
core: | ||
server: | ||
metrics: | ||
collect: | ||
enabled: false | ||
debug: | ||
pprof: | ||
expose: false | ||
stats: | ||
expose: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
app: | ||
debug: true | ||
modules: | ||
log: | ||
level: debug | ||
output: test | ||
trace: | ||
processor: | ||
type: test |
Oops, something went wrong.