Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar authored Jan 10, 2025
0 parents commit bb95d53
Show file tree
Hide file tree
Showing 53 changed files with 2,265 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*/ @ZigBalthazar
*/ @kehiy
7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Description
<!-- Explain the changes you've made and the reason for this pull request. Provide enough context for reviewers to understand your changes. -->

## Related Issue
<!-- If your pull request is related to an existing GitHub issue, link it here. -->

- Fixes #(issue number)
25 changes: 25 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint and format check

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22.5'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
17 changes: 17 additions & 0 deletions .github/workflows/semantic-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Semantic PR

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
139 changes: 139 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- asasalint
- asciicheck
- bidichk
- bodyclose
- decorder
- dogsled
- dupword
- durationcheck
- errchkjson
- errname
- errorlint
- exhaustive
- copyloopvar
- forbidigo
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gocognit
- gocritic
- gocyclo
- godot
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosmopolitan
- grouper
- importas
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
# - musttag
- nakedret
- nilerr
- nilnil
- nlreturn
- nestif
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
- wastedassign
- whitespace
- zerologlint
- nonamedreturns

linters-settings:
gosimple:
checks: ["all"]

govet:
enable-all: true
disable:
- fieldalignment
- contextcheck

predeclared:
# Comma-separated list of predeclared identifiers to not report on.
# Default: ""
ignore: "len"
# Include method names and field names (i.e., qualified names) in checks.
# Default: false
q: true

tagliatelle:
# Check the struct tag name case.
case:
use-field-name: false
rules:
json: snake
yaml: snake

nonamedreturns:
# Report named error if it is assigned inside defer.
# Default: false
report-error-in-defer: false

gocritic:
disabled-checks:
- ifElseChain
- unnamedResult
enabled-tags:
- diagnostic
- style
- performance

nestif:
# Minimal complexity of if statements to report.
# Default: 5
min-complexity: 6

issues:
exclude-rules:
- path: _test.go
linters:
- maintidx
- nestif
- gocognit
- forbidigo
- lll

- path: _easyjson.go
linters:
- nestif

- linters:
- govet
text: 'shadow: declaration of "err" shadows'
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

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 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.

For more information, please refer to <https://unlicense.org>
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Go Echo Boilerplate

This is a golang boilerplate for projects using echo and mongo db stack on Dezh Technologies.

## Stack

* Mongo DB
* Redis
* HTTP/echo
* gRPC/google.grpc

## TODOs

- [ ] Implementing auth middleware.

## Contributions

All kind of contribution are welcome here.

## License

This repo is [unlicensed](./LICENSE).
21 changes: 21 additions & 0 deletions cmd/commands/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package commands

import "fmt"

const help = `Available commands:
Commands:
run <path_to_config> starts the application with the specified configuration file.
help displays this help information.
version displays the version of software.
Usage:
<command> [options]
Examples:
run config.yaml run the application using config.yaml.
help display this help message.
`

func HandleHelp(_ []string) {
fmt.Print(help) //nolint
}
49 changes: 49 additions & 0 deletions cmd/commands/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package commands

import (
"errors"
"os"
"os/signal"
"syscall"

"github.com/dezh-tech/geb/cmd/daemon"
"github.com/dezh-tech/geb/config"
"github.com/dezh-tech/geb/pkg/logger"
)

func HandleRun(args []string) {
if len(args) < 3 {
ExitOnError(errors.New("at least 1 arguments expected\nuse help command for more information"))
}

cfg, err := config.Load(args[2])
if err != nil {
ExitOnError(err)
}

logger.InitGlobalLogger(&cfg.Logger)

d, err := daemon.New(cfg)
if err != nil {
ExitOnError(err)
}

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)

errCh := d.Start()

select {
case sig := <-sigChan:
logger.Info("Initiating graceful shutdown", "signal", sig.String())
if err := d.Stop(); err != nil {
ExitOnError(err)
}

case err := <-errCh:
logger.Error("Initiating shutdown due to the error", "err", err)
if err := d.Stop(); err != nil {
ExitOnError(err)
}
}
}
11 changes: 11 additions & 0 deletions cmd/commands/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package commands

import (
"log"
"os"
)

func ExitOnError(err error) {
log.Printf("immortal error: %s\n", err.Error()) //nolint
os.Exit(1)
}
Loading

0 comments on commit bb95d53

Please sign in to comment.