mirror of
https://github.com/caddyserver/caddy.git
synced 2026-03-17 14:34:03 +00:00
chore: Enable modernize linter (#7519)
This commit is contained in:
@@ -32,6 +32,7 @@ linters:
|
|||||||
- importas
|
- importas
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- misspell
|
- misspell
|
||||||
|
- modernize
|
||||||
- prealloc
|
- prealloc
|
||||||
- promlinter
|
- promlinter
|
||||||
- sloglint
|
- sloglint
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ func (d *Dispenser) File() string {
|
|||||||
// targets are left unchanged. If all the targets are filled,
|
// targets are left unchanged. If all the targets are filled,
|
||||||
// then true is returned.
|
// then true is returned.
|
||||||
func (d *Dispenser) Args(targets ...*string) bool {
|
func (d *Dispenser) Args(targets ...*string) bool {
|
||||||
for i := 0; i < len(targets); i++ {
|
for i := range targets {
|
||||||
if !d.NextArg() {
|
if !d.NextArg() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -616,7 +616,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, p.Errf("Failed to get absolute path of file: %s: %v", importFile, err)
|
return nil, p.Errf("Failed to get absolute path of file: %s: %v", importFile, err)
|
||||||
}
|
}
|
||||||
for i := 0; i < len(importedTokens); i++ {
|
for i := range importedTokens {
|
||||||
importedTokens[i].File = filename
|
importedTokens[i].File = filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ func doHttpCallWithRetries(ctx caddy.Context, client *http.Client, request *http
|
|||||||
var err error
|
var err error
|
||||||
const maxAttempts = 10
|
const maxAttempts = 10
|
||||||
|
|
||||||
for i := 0; i < maxAttempts; i++ {
|
for i := range maxAttempts {
|
||||||
resp, err = attemptHttpCall(client, request)
|
resp, err = attemptHttpCall(client, request)
|
||||||
if err != nil && i < maxAttempts-1 {
|
if err != nil && i < maxAttempts-1 {
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ func (na NetworkAddress) JoinHostPort(offset uint) string {
|
|||||||
func (na NetworkAddress) Expand() []NetworkAddress {
|
func (na NetworkAddress) Expand() []NetworkAddress {
|
||||||
size := na.PortRangeSize()
|
size := na.PortRangeSize()
|
||||||
addrs := make([]NetworkAddress, size)
|
addrs := make([]NetworkAddress, size)
|
||||||
for portOffset := uint(0); portOffset < size; portOffset++ {
|
for portOffset := range size {
|
||||||
addrs[portOffset] = na.At(portOffset)
|
addrs[portOffset] = na.At(portOffset)
|
||||||
}
|
}
|
||||||
return addrs
|
return addrs
|
||||||
|
|||||||
@@ -161,11 +161,11 @@ func (ops *HeaderOps) Provision(_ caddy.Context) error {
|
|||||||
|
|
||||||
// containsPlaceholders checks if the string contains Caddy placeholder syntax {key}
|
// containsPlaceholders checks if the string contains Caddy placeholder syntax {key}
|
||||||
func containsPlaceholders(s string) bool {
|
func containsPlaceholders(s string) bool {
|
||||||
openIdx := strings.Index(s, "{")
|
_, after, ok := strings.Cut(s, "{")
|
||||||
if openIdx == -1 {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
closeIdx := strings.Index(s[openIdx+1:], "}")
|
closeIdx := strings.Index(after, "}")
|
||||||
if closeIdx == -1 {
|
if closeIdx == -1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -442,7 +442,7 @@ func (t Transport) splitPos(path string) int {
|
|||||||
for _, split := range t.SplitPath {
|
for _, split := range t.SplitPath {
|
||||||
splitLen := len(split)
|
splitLen := len(split)
|
||||||
|
|
||||||
for i := 0; i < pathLen; i++ {
|
for i := range pathLen {
|
||||||
if path[i] >= utf8.RuneSelf {
|
if path[i] >= utf8.RuneSelf {
|
||||||
if _, end := splitSearchNonASCII.IndexString(path, split); end > -1 {
|
if _, end := splitSearchNonASCII.IndexString(path, split); end > -1 {
|
||||||
return end
|
return end
|
||||||
@@ -456,7 +456,7 @@ func (t Transport) splitPos(path string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match := true
|
match := true
|
||||||
for j := 0; j < splitLen; j++ {
|
for j := range splitLen {
|
||||||
c := path[i+j]
|
c := path[i+j]
|
||||||
|
|
||||||
if c >= utf8.RuneSelf {
|
if c >= utf8.RuneSelf {
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ func (r *RoundRobinSelection) Select(pool UpstreamPool, _ *http.Request, _ http.
|
|||||||
if n == 0 {
|
if n == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for i := uint32(0); i < n; i++ {
|
for range n {
|
||||||
robin := atomic.AddUint32(&r.robin, 1)
|
robin := atomic.AddUint32(&r.robin, 1)
|
||||||
host := pool[robin%n]
|
host := pool[robin%n]
|
||||||
if host.Available() {
|
if host.Available() {
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ func maskBytes(key [4]byte, pos int, b []byte) int {
|
|||||||
// Mask one word at a time.
|
// Mask one word at a time.
|
||||||
n := (len(b) / wordSize) * wordSize
|
n := (len(b) / wordSize) * wordSize
|
||||||
for i := 0; i < n; i += wordSize {
|
for i := 0; i < n; i += wordSize {
|
||||||
*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i))) ^= kw
|
*(*uintptr)(unsafe.Add(unsafe.Pointer(&b[0]), i)) ^= kw
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mask one byte at a time for remaining bytes.
|
// Mask one byte at a time for remaining bytes.
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func (m *fileMode) UnmarshalJSON(b []byte) error {
|
|||||||
|
|
||||||
// MarshalJSON satisfies json.Marshaler.
|
// MarshalJSON satisfies json.Marshaler.
|
||||||
func (m *fileMode) MarshalJSON() ([]byte, error) {
|
func (m *fileMode) MarshalJSON() ([]byte, error) {
|
||||||
return []byte(fmt.Sprintf("\"%04o\"", *m)), nil
|
return fmt.Appendf(nil, "\"%04o\"", *m), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseFileMode parses a file mode string,
|
// parseFileMode parses a file mode string,
|
||||||
|
|||||||
Reference in New Issue
Block a user