Skip to content

Remove fmt.Print and etc. #115

@dzyanis

Description

@dzyanis

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions