It is possible to execute multiple assignment by if condition, like the following code?
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
}
multiple assignment A form of assignment statement in which the same value is given to two or more variables. For example, in Algol, a := b := c := 0. sets a, b, c to zero. A Dictionary of Computing. "multiple assignment ."
Multiple assignment. I haven't said much about it, but it is legal in C++ to make more than one assignment to the same variable. The effect of the second assignment is to replace the old value of the variable with a new value.
You can assign multiple values to multiple variables by separating variables and values with commas , . You can assign to more than three variables. It is also possible to assign to different types. If there is one variable on the left side, it is assigned as a tuple.
Python allows you to assign a single value to several variables simultaneously. For example − a = b = c = 1. Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables.
It looks like you want something like this:
package main
import "fmt"
func a(int) int { return 7 }
func b(int) int { return 42 }
func main() {
if x, y := a(1), b(2); x > 0 && x < y {
fmt.Println("sometimes")
}
fmt.Println("always")
}
Output:
sometimes
always
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With