Create a gist now

Instantly share code, notes, and snippets.

@caike /go.go
Last active Apr 28, 2016

What would you like to do?
Unlearning Rubyisms
// first stab
const defaultPort = "8080"
func getPort() string {
portEnv := os.Getenv("PORT")
if portEnv != "" {
return portEnv
}
return defaultPort
}
// idiomatic Go
const defaultPort = "8080"
func getPort() string {
portEnv, portIsSet := os.LookupEnv("PORT")
if portIsSet {
return portEnv
}
return defaultPort
}
DEFAULT_PORT = "8080"
def get_port
ENV["PORT"] || DEFAULT_PORT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment