1. Scenario:
When the program reports an error, you want a fixed error message to perform the operations done by the corresponding code logic:
2. Code:
import strings
if errCheck != nil {
if strings.Contains(errCheck.Error(), "Table 'opstyu.checkdb' doesn't exist") {
// 表示表checkdb不存在,就是没有跑过校验数据
return "1","2"
} else {
initlog.Error.Println(errCheck)
}
}
The above code means: look at whether the errCheck.Error() error message contains the following string ("Table'opstyu.checkdb' doesn't exist"), if it contains, then execute the following logic
3. The reason for this:
The information from errCheck.Error() has spaces and various unnecessary information is printed out. It is not easy to judge. It is the best way to judge whether it contains