Multiple assignment by if statement

前端 未结 2 1796
借酒劲吻你
借酒劲吻你 2021-02-06 09:30

It is possible to execute multiple assignment by if condition, like the following code?

func SendEmail(url, email string) (string, error) {

    genUri := buildU         


        
2条回答
  •  情深已故
    2021-02-06 10:28

    No. Only one 'simple statement' is permitted at the beginning of an if-statement, per the spec.

    The recommended approach is multiple tests which might return an error, so I think you want something like:

    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
    }
    

提交回复
热议问题