lint (#2)
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 1m5s

Reviewed-on: Siteworxpro/Go-Template#2
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit is contained in:
2025-06-18 02:16:10 +00:00
committed by Siteworx Pro Gitea
parent 68cf45fc49
commit 12bbacced0
5 changed files with 74 additions and 7 deletions

38
.gitea/workflows/lint.yml Normal file
View File

@@ -0,0 +1,38 @@
on:
push:
branches:
- "*"
name: 🧪 ✨ Unit Tests Workflow
jobs:
test-go:
env:
GO_VERSION: '1.24.3'
NODE_TLS_REJECT_UNAUTHORIZED: 0
name: 🔍 🐹 Go Tests
runs-on: ubuntu-latest
steps:
- name: 🛡️ 🔒 Add Siteworx CA Certificates
run: |
curl -Ls https://siteworxpro.com/hosted/Siteworx+Root+CA.pem -o /usr/local/share/ca-certificates/sw.crt
update-ca-certificates
- name: ⚙️ 🐹 Set up Go Environment
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: 📖 🔍 Checkout Repository Code
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: 📦 📥 Install Dependencies
run: |
go mod download
- name: ✅ 🔍 Run Go Lint
uses: golangci/golangci-lint-action@v8.0.0

27
.golangci.yml Normal file
View File

@@ -0,0 +1,27 @@
version: "2"
linters:
default: standard
enable:
- whitespace
- tagalign
- reassign
- bodyclose
- contextcheck
- containedctx
- godot
- usestdlibvars
- funlen
- gochecknoglobals
- tagalign
- sqlclosecheck
- rowserrcheck
- recvcheck
- reassign
- predeclared
- maintidx
- mnd
formatters:
settings:
gofmt:
simplify: true

View File

@@ -4,6 +4,7 @@ import (
"gitea.siteworxpro.com/Siteworxpro/Go-Template/http_handlers/errors" "gitea.siteworxpro.com/Siteworxpro/Go-Template/http_handlers/errors"
"gitea.siteworxpro.com/Siteworxpro/Go-Template/logger" "gitea.siteworxpro.com/Siteworxpro/Go-Template/logger"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"net/http"
) )
func Register(g *echo.Group) { func Register(g *echo.Group) {
@@ -20,7 +21,7 @@ type index struct{}
func (i *index) Get(c echo.Context) error { func (i *index) Get(c echo.Context) error {
c.Get("logger").(logger.Interface).Info("Index handler called") c.Get("logger").(logger.Interface).Info("Index handler called")
return c.JSON(200, map[string]string{"message": "Hello, World!"}) return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"})
} }
func (i *index) Post(c echo.Context) error { func (i *index) Post(c echo.Context) error {
@@ -28,11 +29,11 @@ func (i *index) Post(c echo.Context) error {
} }
func (i *index) Put(c echo.Context) error { func (i *index) Put(c echo.Context) error {
return c.JSON(200, map[string]string{"message": "Hello, World!"}) return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"})
} }
func (i *index) Delete(c echo.Context) error { func (i *index) Delete(c echo.Context) error {
return c.JSON(200, map[string]string{"message": "Hello, World!"}) return c.JSON(http.StatusOK, map[string]string{"message": "Hello, World!"})
} }
func (i *index) Patch(c echo.Context) error { func (i *index) Patch(c echo.Context) error {

View File

@@ -5,7 +5,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
const contextKey = "logger" type contextKeyType string
const contextKey contextKeyType = "logger"
type Interface interface { type Interface interface {
Info(format string, args ...interface{}) Info(format string, args ...interface{})
@@ -19,7 +21,7 @@ type Logger struct {
logger *log.Logger logger *log.Logger
} }
func FromContext(ctx context.Context) Interface { func FromContext(ctx context.Context) *Logger {
logger, ok := ctx.Value(contextKey).(*Logger) logger, ok := ctx.Value(contextKey).(*Logger)
if !ok { if !ok {
return nil return nil
@@ -28,7 +30,7 @@ func FromContext(ctx context.Context) Interface {
return logger return logger
} }
func NewLogger(level log.Level) Interface { func NewLogger(level log.Level) *Logger {
l := log.New() l := log.New()
l.SetFormatter(&log.JSONFormatter{}) l.SetFormatter(&log.JSONFormatter{})
l.SetLevel(level) l.SetLevel(level)

View File

@@ -12,7 +12,6 @@ import (
const Version = "0.1" const Version = "0.1"
func main() { func main() {
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "Go-Template", Use: "Go-Template",
Short: "Go-Template is a simple template for Go applications", Short: "Go-Template is a simple template for Go applications",