lint (#2)
All checks were successful
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 1m5s
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:
38
.gitea/workflows/lint.yml
Normal file
38
.gitea/workflows/lint.yml
Normal 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
27
.golangci.yml
Normal 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
|
@@ -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 {
|
||||||
|
@@ -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)
|
||||||
|
1
main.go
1
main.go
@@ -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",
|
||||||
|
Reference in New Issue
Block a user