Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ jobs:
- macos-latest
- windows-latest
go:
- '1.20'
- '1.21'
- '1.22'

include:
# Set the minimum Go patch version for the given Go minor
# Usable via ${{ matrix.GO_SEMVER }}
- go: '1.20'
GO_SEMVER: '~1.20.6'

- go: '1.21'
GO_SEMVER: '~1.21.0'

- go: '1.22'
GO_SEMVER: '~1.22.0-rc.2'

# Set some variables per OS, usable via ${{ matrix.VAR }}
# CADDY_BIN_PATH: the path to the compiled Caddy binary, for artifact publishing
# SUCCESS: the typical value for $? per OS (Windows/pwsh returns 'True')
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/cross-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
- 'darwin'
- 'netbsd'
go:
- '1.21'
- '1.22'

include:
# Set the minimum Go patch version for the given Go minor
# Usable via ${{ matrix.GO_SEMVER }}
- go: '1.21'
GO_SEMVER: '~1.21.0'
- go: '1.22'
GO_SEMVER: '~1.22.0-rc.2'

runs-on: ubuntu-latest
continue-on-error: true
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '~1.21.0'
go-version: '~1.22.0-rc.2'
check-latest: true

# Workaround for https://github.com/golangci/golangci-lint-action/issues/135
skip-pkg-cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
version: v1.55

# Workaround for https://github.com/golangci/golangci-lint-action/issues/135
skip-pkg-cache: true
Expand All @@ -57,5 +54,5 @@ jobs:
- name: govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: '~1.21.0'
go-version-input: '~1.22.0-rc.2'
check-latest: true
82 changes: 69 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,116 @@ linters-settings:
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true
exhaustive:
ignore-enum-types: reflect.Kind|svc.Cmd

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errname
- exhaustive
- exportloopref
- gci
- gofmt
- goimports
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- importas
- misspell
- prealloc
- promlinter
- sloglint
- sqlclosecheck
- staticcheck
- tenv
- testableexamples
- testifylint
- tparallel
- typecheck
- unconvert
- unused
- wastedassign
- whitespace
- zerologlint
# these are implicitly disabled:
# - asciicheck
# - containedctx
# - contextcheck
# - cyclop
# - depguard
# - dogsled
# - dupl
# - exhaustive
# - exportloopref
# - errchkjson
# - errorlint
# - exhaustruct
# - execinquery
# - exhaustruct
# - forbidigo
# - forcetypeassert
# - funlen
# - gci
# - ginkgolinter
# - gocheckcompilerdirectives
# - gochecknoglobals
# - gochecknoinits
# - gochecksumtype
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
# - gofumpt
# - goheader
# - golint
# - gomnd
# - gomoddirectives
# - gomodguard
# - goprintffuncname
# - interfacer
# - gosmopolitan
# - grouper
# - inamedparam
# - interfacebloat
# - ireturn
# - lll
# - maligned
# - loggercheck
# - maintidx
# - makezero
# - mirror
# - musttag
# - nakedret
# - nestif
# - nilerr
# - nilnil
# - nlreturn
# - noctx
# - nolintlint
# - nonamedreturns
# - nosprintfhostport
# - paralleltest
# - perfsprint
# - predeclared
# - protogetter
# - reassign
# - revive
# - rowserrcheck
# - scopelint
# - sqlclosecheck
# - stylecheck
# - tagalign
# - tagliatelle
# - testpackage
# - thelper
# - unparam
# - whitespace
# - usestdlibvars
# - varnamelen
# - wrapcheck
# - wsl

run:
Expand Down Expand Up @@ -110,3 +163,6 @@ issues:
text: 'G404' # G404: Insecure random number source (rand)
linters:
- gosec
- path: modules/logging/filters.go
linters:
- dupl
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ See [our online documentation](https://caddyserver.com/docs/install) for other i

Requirements:

- [Go 1.20 or newer](https://golang.org/dl/)
- [Go 1.21 or newer](https://golang.org/dl/)

### For development

Expand Down
2 changes: 1 addition & 1 deletion caddyconfig/caddyfile/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf
return nil, warnings, err
}

// lint check: see if input was properly formatted; sometimes messy files files parse
// lint check: see if input was properly formatted; sometimes messy files parse
// successfully but result in logical errors (the Caddyfile is a bad format, I'm sorry)
if warning, different := FormattingDifference(filename, body); different {
warnings = append(warnings, warning)
Expand Down
2 changes: 1 addition & 1 deletion caddyconfig/caddyfile/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (l *lexer) next() (bool, error) {
}

// check if we're done, i.e. that the last few characters are the marker
if len(val) > len(heredocMarker) && heredocMarker == string(val[len(val)-len(heredocMarker):]) {
if len(val) >= len(heredocMarker) && heredocMarker == string(val[len(val)-len(heredocMarker):]) {
// set the final value
val, err = l.finalizeHeredoc(val, heredocMarker)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions caddyconfig/caddyfile/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ EOF same-line-arg
},
{
input: []byte(`heredoc <<EOF
EOF
HERE same-line-arg
`),
expected: []Token{
{Line: 1, Text: `heredoc`},
{Line: 1, Text: ``},
{Line: 3, Text: `HERE`},
{Line: 3, Text: `same-line-arg`},
},
},
{
input: []byte(`heredoc <<EOF
EOF same-line-arg
`),
expected: []Token{
Expand Down
1 change: 0 additions & 1 deletion caddytest/caddytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {

tc.t.Cleanup(func() {
if tc.t.Failed() && tc.configLoaded {

res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
if err != nil {
tc.t.Log("unable to read the current config")
Expand Down
29 changes: 26 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"encoding/json"
"fmt"
"log"
"log/slog"
"reflect"

"github.com/caddyserver/certmagic"
"go.uber.org/zap"
"go.uber.org/zap/exp/zapslog"

"github.com/caddyserver/caddy/v2/internal/filesystems"
)
Expand Down Expand Up @@ -176,7 +178,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
return nil, err
}
result = val

} else if isJSONRawMessage(typ.Elem()) {
// val is `[]json.RawMessage`

Expand All @@ -192,7 +193,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
all = append(all, val)
}
result = all

} else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {
// val is `[][]json.RawMessage`

Expand All @@ -213,7 +213,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
all = append(all, allInner)
}
result = all

} else if isModuleMapType(typ.Elem()) {
// val is `[]map[string]json.RawMessage`

Expand Down Expand Up @@ -506,6 +505,30 @@ func (ctx Context) Logger(module ...Module) *zap.Logger {
return ctx.cfg.Logging.Logger(mod)
}

// Slogger returns a slog logger that is intended for use by
// the most recent module associated with the context.
func (ctx Context) Slogger() *slog.Logger {
if ctx.cfg == nil {
// often the case in tests; just use a dev logger
l, err := zap.NewDevelopment()
if err != nil {
panic("config missing, unable to create dev logger: " + err.Error())
}
return slog.New(zapslog.NewHandler(l.Core(), nil))
}
mod := ctx.Module()
if mod == nil {
return slog.New(zapslog.NewHandler(Log().Core(), nil))
}

return slog.New(zapslog.NewHandler(
ctx.cfg.Logging.Logger(mod).Core(),
&zapslog.HandlerOptions{
LoggerName: string(mod.CaddyModule().ID),
},
))
}

// Modules returns the lineage of modules that this context provisioned,
// with the most recent/current module being last in the list.
func (ctx Context) Modules() []Module {
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/caddyserver/caddy/v2

go 1.20
go 1.21

toolchain go1.21.4

require (
github.com/BurntSushi/toml v1.3.2
Expand All @@ -16,7 +18,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5
github.com/mholt/acmez v1.2.0
github.com/prometheus/client_golang v1.18.0
github.com/quic-go/quic-go v0.40.1
github.com/quic-go/quic-go v0.41.0
github.com/smallstep/certificates v0.25.0
github.com/smallstep/nosql v0.6.0
github.com/smallstep/truststore v0.12.1
Expand All @@ -33,6 +35,7 @@ require (
go.opentelemetry.io/otel/sdk v1.21.0
go.uber.org/automaxprocs v1.5.3
go.uber.org/zap v1.26.0
go.uber.org/zap/exp v0.2.0
golang.org/x/crypto v0.18.0
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611
golang.org/x/net v0.19.0
Expand All @@ -59,7 +62,6 @@ require (
github.com/onsi/ginkgo/v2 v2.13.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
github.com/smallstep/go-attestation v0.4.4-0.20230627102604-cf579e53cbd2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
Expand Down
Loading