Skip to content

best practice for interface assertion? #3662

Closed Answered by seaguest
seaguest asked this question in Q&A
Discussion options

You must be logged in to vote
seaguest@DEV:~/Work/monitor/test$ golangci-lint version
golangci-lint has version 1.51.2 built from 3e8facb4 on 2023-02-19T21:43:54Z
seaguest@DEV:~/Work/monitor/test$ 
seaguest@DEV:~/Work/monitor/test$ 
seaguest@DEV:~/Work/monitor/test$ cat t4.go
package main

import (
    "errors"
)

var _ error = (*ValidationError)(nil)

type ValidationError struct {
    Msg string
}

func (v *ValidationError) Error() string {
    return v.Msg
}

func main() {
    foo("huu")
}

func foo(a string) error {
    if a == "a" {
        return errors.New("OOPS")
    }

    return nil
}
seaguest@DEV:~/Work/monitor/test$ golangci-lint run -Eerrcheck 
t4.go:7:5: Error return value is not checked (errcheck)
var _ …

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@seaguest
Comment options

@ldez
Comment options

@seaguest
Comment options

@ldez
Comment options

@seaguest
Comment options

Answer selected by ldez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants