Last active
December 18, 2015 17:19
-
-
Save akhenakh/5818109 to your computer and use it in GitHub Desktop.
Learning Golang from a Pythonista if "foo" in alist:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lookup for the users table create it otherwise | |
// var tables []string and StringSlice are equivalent | |
var tables sort.StringSlice | |
err = r.TableList().Run(session).All(&tables) | |
if err != nil { | |
log.Panic(err) | |
} | |
// I miss python if "users" in tables | |
exists := false | |
for _, element := range tables { | |
if element == "users" { | |
exists = true | |
break | |
} | |
} | |
if !exists { | |
err = r.TableCreate("users").Run(session).Exec() | |
if err != nil { | |
log.Panic(err) | |
} | |
} | |
// but you still can | |
sort.Sort(tables) | |
if sort.SearchStrings(tables, "users") != 0 { | |
err = r.TableCreate("users").Run(session).Exec() | |
if err != nil { | |
log.Panic(err) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment