2 Commits

Author SHA1 Message Date
6dd76f2667 Add Go linting job to unit tests workflow (#3)
All checks were successful
🧪 ✨ Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 1m2s
🧪 ✨ Tests Workflow / 🔍 🐹 Go Lint (push) Successful in 1m23s
Reviewed-on: Siteworxpro/Go-Template#3
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
2025-06-18 02:22:57 +00:00
12bbacced0 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>
2025-06-18 02:16:10 +00:00
5 changed files with 71 additions and 11 deletions

View File

@@ -1,15 +1,44 @@
on:
workflow_dispatch: {}
push:
branches:
- "*"
name: 🧪 ✨ Unit Tests Workflow
name: 🧪 ✨ Tests Workflow
env:
GO_VERSION: '1.24.3'
jobs:
lint-go:
name: 🔍 🐹 Go Lint
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
test-go:
env:
GO_VERSION: '1.24.3'
NODE_TLS_REJECT_UNAUTHORIZED: 0
name: 🔍 🐹 Go Tests
runs-on: ubuntu-latest
steps:
@@ -39,6 +68,8 @@ jobs:
go test -v ./... -coverprofile=coverage.out
- name: 📊 📈 Upload Coverage Report
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
uses: christopherhx/gitea-upload-artifact@v4
with:
name: coverage-report

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/logger"
"github.com/labstack/echo/v4"
"net/http"
)
func Register(g *echo.Group) {
@@ -20,7 +21,7 @@ type index struct{}
func (i *index) Get(c echo.Context) error {
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 {
@@ -28,11 +29,11 @@ func (i *index) Post(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 {
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 {

View File

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

View File

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