This is a creation in Article, where the information may have evolved or changed.
Many people like the Golang interface, which can be implemented without declaring it; but I prefer Golang's variable derivation and if expression, and look at the following piece of code:
var ok bool var vhost *srsvhost if Vid,err: = Bravo_json_get_number (Stream, "vhost"); Err! = Nil {return err} else if Vhost,ok = Vhosts[vid];!ok {retur n Errors. New (FMT. Sprintf ("Vhost id=%v not Found", vid))} else {fmt. Println ("Vid is", vid, ", Vhost is", Vhost)} var sid string if App,err: = BR Avo_json_get_string (Stream, "app"); Err! = Nil {return err} else if sname,err: = Bravo_json_get_string (Stream, "name"); Err! = Nil {return err} else {//all streams maps to default vhost. Sid = Fmt. Sprintf ("__defaultvhost__/%s/%s", App, Sname)} fmt. PRINTLN ("Sid is", sid, ", Vhost is", Vhost)
This place, in fact, should also have vid/app/sname three local variables, using Golang variable derivation and if expression, are limited to a smaller scope.
The variable is reduced, the scope is limited, and the code is read better.