This question already has an answer here:
I want to set a string to one of two things based on an if/else statement:
var output string
password, ok := m["password"]
if ok {
output := runcmd("connect.sh "+ssid+" "+password)
} else {
output := runcmd("connect.sh "+ssid)
}
fmt.Println(output)
During compile I get back:
output declared and not used
I understand that this is because output
is a local variable inside ok { ... }
, what would the proper way to do this be?
Also tried using a capital for Output
as I've had to do that to make struct properties accessible before.
</div>