Skip to content

Commit

Permalink
additional linting
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Aug 14, 2023
1 parent 14743fd commit 3b0dc49
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ linters-settings:
disabled: true
- name: defer
disabled: true
- name: nested-structs
disabled: true
- name: unhandled-error
disabled: false
arguments:
- 'buf.WriteString'
- 'buf.WriteRune'
- 'sb.WriteString'
- 'fmt.Printf'
- 'fmt.Print'
- 'fmt.Println'
Expand Down
4 changes: 2 additions & 2 deletions caddyconfig/caddyfile/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ func Format(input []byte) []byte {
spacePrior := space
space = false

//////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////
// I find it helpful to think of the formatting loop in two
// main sections; by the time we reach this point, we
// know we are in a "regular" part of the file: we know
// the character is not a space, not in a literal segment
// like a comment or quoted, it's not escaped, etc.
//////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////

if ch == '#' {
comment = true
Expand Down
4 changes: 2 additions & 2 deletions cmd/packagesfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func getModules() (standard, nonstandard, unknown []moduleInfo, err error) {
bi, ok := debug.ReadBuildInfo()
if !ok {
err = fmt.Errorf("no build info")
return
return standard, nonstandard, unknown, err
}

for _, modID := range caddy.Modules() {
Expand Down Expand Up @@ -222,7 +222,7 @@ func getModules() (standard, nonstandard, unknown []moduleInfo, err error) {
nonstandard = append(nonstandard, caddyModGoMod)
}
}
return
return standard, nonstandard, unknown, nil
}

func listModules(path string) error {
Expand Down
6 changes: 3 additions & 3 deletions listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ func SplitNetworkAddress(a string) (network, host, port string, err error) {
}
if IsUnixNetwork(network) {
host = a
return
return network, host, "", nil
}
host, port, err = net.SplitHostPort(a)
if err == nil || a == "" {
return
return network, host, port, nil
}
// in general, if there was an error, it was likely "missing port",
// so try adding a bogus port to take advantage of standard library's
Expand All @@ -408,7 +408,7 @@ func SplitNetworkAddress(a string) (network, host, port string, err error) {
err = nil
port = ""
}
return
return network, host, port, err
}

// JoinNetworkAddress combines network, host, and port into a single
Expand Down
4 changes: 2 additions & 2 deletions modules/caddyhttp/fileserver/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (m MatchFile) selectFile(r *http.Request) (matched bool) {
for _, pattern := range m.TryFiles {
if err := parseErrorCode(pattern); err != nil {
caddyhttp.SetVar(r.Context(), caddyhttp.MatcherErrorVarKey, err)
return
return false
}
candidates := makeCandidates(pattern)
for _, c := range candidates {
Expand Down Expand Up @@ -480,7 +480,7 @@ func (m MatchFile) selectFile(r *http.Request) (matched bool) {
return true
}

return
return false
}

// parseErrorCode checks if the input is a status
Expand Down
4 changes: 2 additions & 2 deletions modules/caddyhttp/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ func errLogValues(err error) (status int, msg string, fields []zapcore.Field) {
zap.String("err_id", handlerErr.ID),
zap.String("err_trace", handlerErr.Trace),
}
return
return status, msg, fields
}
status = http.StatusInternalServerError
msg = err.Error()
return
return status, msg, fields
}

// ExtraLogFields is a list of extra fields to log with every request.
Expand Down
2 changes: 1 addition & 1 deletion modules/caddyhttp/requestbody/requestbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (ew errorWrapper) Read(p []byte) (n int, err error) {
if err != nil && err.Error() == "http: request body too large" {
err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err)
}
return
return n, err
}

// Interface guard
Expand Down
10 changes: 5 additions & 5 deletions modules/caddyhttp/reverseproxy/fastcgi/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ func (rec *record) fill(r io.Reader) (err error) {
rec.lr.N = rec.padding
rec.lr.R = r
if _, err = io.Copy(io.Discard, rec); err != nil {
return
return err
}

if err = binary.Read(r, binary.BigEndian, &rec.h); err != nil {
return
return err
}
if rec.h.Version != 1 {
err = errors.New("fcgi: invalid header version")
return
return err
}
if rec.h.Type == EndRequest {
err = io.EOF
return
return err
}
rec.lr.N = int64(rec.h.ContentLength)
rec.padding = int64(rec.h.PaddingLength)
return
return nil
}

func (rec *record) Read(p []byte) (n int, err error) {
Expand Down
4 changes: 2 additions & 2 deletions modules/caddyhttp/reverseproxy/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ func (m *maxLatencyWriter) Write(p []byte) (n int, err error) {
if m.latency < 0 {
//nolint:errcheck
m.flush()
return
return n, err
}
if m.flushPending {
return
return n, err
}
if m.t == nil {
m.t = time.AfterFunc(m.latency, m.delayedFlush)
Expand Down
2 changes: 1 addition & 1 deletion modules/caddyhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (s *Server) findLastRouteWithHostMatcher() int {
found := (func() bool {
for _, sets := range route.MatcherSets {
for _, matcher := range sets {
switch matcher.(type) {
switch matcher.(type) { //nolint:revive // ignore SA9003: type switch is idiomatic
case *MatchHost:
foundHostMatcher = true
return true
Expand Down
6 changes: 3 additions & 3 deletions modules/caddypki/adminapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ func (a *adminAPI) getCAFromAPIRequestPath(r *http.Request) (*CA, error) {
func rootAndIntermediatePEM(ca *CA) (root, inter []byte, err error) {
root, err = pemEncodeCert(ca.RootCertificate().Raw)
if err != nil {
return
return nil, nil, err
}
inter, err = pemEncodeCert(ca.IntermediateCertificate().Raw)
if err != nil {
return
return nil, nil, err
}
return
return root, inter, nil
}

// caInfo is the response structure for the CA info API endpoint.
Expand Down
8 changes: 4 additions & 4 deletions modules/logging/netwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (reconn *redialerConn) Write(b []byte) (n int, err error) {
reconn.connMu.RUnlock()
if conn != nil {
if n, err = conn.Write(b); err == nil {
return
return n, nil
}
}

Expand All @@ -182,7 +182,7 @@ func (reconn *redialerConn) Write(b []byte) (n int, err error) {
// one of them might have already re-dialed by now; try writing again
if reconn.Conn != nil {
if n, err = reconn.Conn.Write(b); err == nil {
return
return n, nil
}
}

Expand All @@ -196,7 +196,7 @@ func (reconn *redialerConn) Write(b []byte) (n int, err error) {
if err2 != nil {
// logger socket still offline; instead of discarding the log, dump it to stderr
os.Stderr.Write(b)
return
return 0, err2
}
if n, err = conn2.Write(b); err == nil {
if reconn.Conn != nil {
Expand All @@ -209,7 +209,7 @@ func (reconn *redialerConn) Write(b []byte) (n int, err error) {
os.Stderr.Write(b)
}

return
return n, err
}

func (reconn *redialerConn) dial() (net.Conn, error) {
Expand Down

0 comments on commit 3b0dc49

Please sign in to comment.