diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..ec0016b --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -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 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..45d32d5 --- /dev/null +++ b/.golangci.yml @@ -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 \ No newline at end of file diff --git a/http_handlers/index/index.go b/http_handlers/index/index.go index f3fab97..ab95ed8 100644 --- a/http_handlers/index/index.go +++ b/http_handlers/index/index.go @@ -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 { diff --git a/logger/log.go b/logger/log.go index c923082..e5518a2 100644 --- a/logger/log.go +++ b/logger/log.go @@ -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) diff --git a/main.go b/main.go index 40b3a88..7817124 100644 --- a/main.go +++ b/main.go @@ -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",