示例:
err := fmt.Errorf("Cannot read the file!")
log.Printf("Reading %s: %v", file, err)
根据 golang.org 上的 Error Strings 页面,错误字符串不应大写或以标点符号结尾,因为它们可能会出现在其他上下文中。
要修正格式,可以应用修正错误字符串格式快速修复。 应用快速修复后,错误字符串将如下所示:
err := fmt.Errorf("cannot read the file")
log.Printf("Reading %s: %v", file, err)