On Mon, Jun 26, 2017 at 8:50 PM, Wang Sheng <wans...@gmail.com> wrote: > I am new for golang, I think following code is too redundant , is there any > way simplify it ? > > name, ok := fieldsMap["name"] > if !ok { > name = "" > }
One thing to consider if that ok is false, name is set to the zero value. So the `if !ok { name = "" }` is unnecessary; if ok is false, name is sure to be "" already. Also, fieldsMap["name"] will evaluate to "" if "name" is not in fieldsMap, so you don't really need the `name` variable at all; you can just use fieldsMap["name"] in the db.Exec call. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.