I have two questions about Go code. This is my program. This program controls the presence of a nickname in a "database".
package main
import "fmt"
func rcv(){
if r := recover() ; r != nil {
fmt.Println("retry.")
main()
}
}
func main(){
defer rcv()
INSERT:
fmt.Println("Insert a nickname: ")
var s string
fmt.Scanln(&s)
switch {
case len(s) <= 0 :
fmt.Println(fmt.Errorf("error empty"))
goto INSERT
case s=="mark"||s=="andrea":
fmt.Println("Accept, the nickname is",s)
default :
fmt.Println("ATTENTION, nickname not found")
panic("Error.")
}
}
My questions are:
Using the recover function ( rcv () ), at the end of it, the recalled of main() is sent running like another thread? The principal main() function ends when the second is executed or whenever the panic is raised, the recover function create another process? (example: if the input nickname is wrong 5 times, 5 more main functions are started, so 6 Main running functions?) If create multiple executions of the main(), is there a way to print threads/process id or something like that?
I used the INSERT label and the goto construct. Can I use goto outside the main function (example: at the end of the rcv() function to return to the top of the main function)? I could use goto instead of calling the main() function at the end of the rcv()