是否可以通过if条件执行多个分配,如以下代码?
func SendEmail(url, email string) (string, error) { genUri := buildUri() if err := setRedisIdentity(genUri, email); err != nil; genUrl, err := buildActivateUrl(url, genUri); { return "", err } return "test", nil }
否。根据规范,在if语句的开头仅允许一个“简单语句” 。
该建议的方法是这可能会返回一个错误,所以我想你想是多重考验:
func SendEmail(url, email string) (string, error) { genUri := buildUri() if err := setRedisIdentity(genUri, email); err != nil { return "", err } if genUrl, err := buildActivateUrl(url, genUri); err != nil { return "", err } return "test", nil }