Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fmt.Print and etc. #115

Open
dzyanis opened this issue Mar 18, 2022 · 0 comments
Open

Remove fmt.Print and etc. #115

dzyanis opened this issue Mar 18, 2022 · 0 comments

Comments

@dzyanis
Copy link
Contributor

dzyanis commented Mar 18, 2022

fmt.Print, fmt.Printf, fmt.Println and etc. can clog output. For example: a report of go test. Also, we can't test it.

If we use it for logging then lets just use logger instead.
If we really want to throw some message to the stdout then we can use io.Writer

func message(w io.Writer) error {
    _, err := w.Write([]byte("message"))
    return err
}

or just return the message

func message() (string, error)  {
    return "message", nil
}

and handle somewhere in the main func.

The linter forbidigo can catch such cases. I'd recommend to enable it.

provider/nowsms/nowsms.go:67:2: use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
        fmt.Println("Message sent: ", message.Text)
        ^
provider/tencentcloud/tencentcloud.go:79:4: use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
                        fmt.Printf("An API error has returned: %s", err)
                        ^
provider/tencentcloud/tencentcloud.go:87:3: use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
                fmt.Printf("%s", b)
                ^
provider/kavenegar/kavenegar.go:64:2: use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
        fmt.Println("Message sent: ", message.Text)
        ^
provider/ghasedak/ghasedak.go:63:2: use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
        fmt.Println("Message sent: ", message.Text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant