diff --git a/.gitignore b/.gitignore index ee10409..3feaa0c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ go.work bin/ -out/ \ No newline at end of file +out/ + +.task/ diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..e36268a --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,92 @@ +linters-settings: + dupl: + threshold: 100 + funlen: + lines: 100 + statements: 50 + gci: + local-prefixes: github.com/CallumKerson/Athenaeum + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + - wrapperFunc + gocyclo: + min-complexity: 15 + goimports: + local-prefixes: github.com/CallumKerson/Athenaeum + gosec: + config: + G306: "0755" + govet: + check-shadowing: true + lll: + line-length: 140 + misspell: + locale: UK + nolintlint: + allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + +linters: + disable-all: true + enable: + - bodyclose + - dogsled + - dupl + - errcheck + - exportloopref + - exhaustive + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - goerr113 + - gofmt + - goimports + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - makezero + - makezero + - misspell + - nakedret + - noctx + - nolintlint + - prealloc + - predeclared + - rowserrcheck + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varnamelen + - whitespace + +issues: + exclude-rules: + - path: _test\.go + linters: + - lll + - funlen + - bodyclose + - gosec diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ff6f8f4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/Bahjat/pre-commit-golang + rev: v1.0.2 + hooks: + - id: go-fmt-import + - id: go-vet + - id: go-lint + - id: go-unit-tests + - id: golangci-lint # requires github.com/golangci/golangci-lint diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..f7020b9 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,47 @@ +# https://taskfile.dev + +version: "3" + +tasks: + #unix setup + setup: + - brew update + - brew install go goimports-reviser golangci-lint pre-commit yq + - pre-commit install + + #local tasks + go:mod-tidy: + - go mod tidy + + go:fmt: + - gofmt -l -s -w . + + go:lint: + - golangci-lint run + + go:isort: + - goimports-reviser -rm-unused -company-prefixes github.com/CallumKerson -project-name github.com/CallumKerson/Athenaeum -use-cache -format ./... + + test: + - go test ./... + + compile: + desc: "Compiles for the current OS and architecture" + cmds: + - go build -ldflags "-s -w" -o bin/ ./... + + tidy: + desc: "Tidies the go project" + cmds: + - task: go:mod-tidy + - task: go:fmt + - task: go:isort + - task: go:lint + - pre-commit run + + build: + desc: "Builds the go project" + cmds: + - task: tidy + - task: test + - task: compile diff --git a/go.mod b/go.mod index 6695533..18ee203 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module github.com/CallumKerson/Athenaeum go 1.20 + +require ( + github.com/CallumKerson/loggerrific v1.0.1 + github.com/sirupsen/logrus v1.9.0 +) + +require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..83331e6 --- /dev/null +++ b/go.sum @@ -0,0 +1,17 @@ +github.com/CallumKerson/loggerrific v1.0.1 h1:ooe171INnDGUku/7eXe2aX6xJmCNHSLsyZexNJvrTH0= +github.com/CallumKerson/loggerrific v1.0.1/go.mod h1:jJg0jUNE6bIEqSOuPuNG+YBZVCsTOb80/7x18bz7Sqk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/adapters/logrus/logrus.go b/internal/adapters/logrus/logrus.go new file mode 100644 index 0000000..65defcc --- /dev/null +++ b/internal/adapters/logrus/logrus.go @@ -0,0 +1,64 @@ +package logrus + +import ( + "github.com/sirupsen/logrus" + + "github.com/CallumKerson/loggerrific" +) + +type Logger struct { + *logrus.Logger +} + +func NewLogger() *Logger { + logrusLogger := &Logger{ + logrus.New(), + } + logrusLogger.SetLevel(logrus.InfoLevel) + + return logrusLogger +} + +func (l *Logger) WithField(key string, value interface{}) loggerrific.Entry { + return l.Logger.WithField(key, value) +} + +func (l *Logger) WithFields(fields map[string]interface{}) loggerrific.Entry { + return l.Logger.WithFields(fields) +} + +func (l *Logger) WithError(err error) loggerrific.Entry { + return l.Logger.WithError(err) +} + +func (l *Logger) SetLevelDebug() { + l.SetLevel(logrus.DebugLevel) +} + +func (l *Logger) SetLevelInfo() { + l.SetLevel(logrus.InfoLevel) +} + +func (l *Logger) SetLevelWarn() { + l.SetLevel(logrus.WarnLevel) +} + +func (l *Logger) SetLevelError() { + l.SetLevel(logrus.ErrorLevel) +} + +func (l *Logger) IsDebugEnabled() bool { + return l.IsLevelEnabled(logrus.DebugLevel) +} + +func (l *Logger) IsInfoEnabled() bool { + return l.IsLevelEnabled(logrus.InfoLevel) +} + +func (l *Logger) IsWarnEnabled() bool { + return l.IsLevelEnabled(logrus.WarnLevel) +} + +func (l *Logger) IsErrorEnabled() bool { + return l.IsLevelEnabled(logrus.ErrorLevel) +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..424af75 --- /dev/null +++ b/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "os" + + "github.com/CallumKerson/loggerrific" + + "github.com/CallumKerson/Athenaeum/internal/adapters/logrus" +) + +func Run(logger loggerrific.Logger) error { + logger.Infoln("Setting up Server") + + return nil +} + +func main() { + logger := logrus.NewLogger() + logger.SetLevelDebug() + + if err := Run(logger); err != nil { + logger.WithError(err).Errorln("Error starting up server") + os.Exit(1) + } +}