Last active
January 3, 2016 08:19
-
-
Save bobrik/8435500 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import "flag" | |
import "os" | |
import "strconv" | |
import "fmt" | |
var port *int | |
func init() { | |
defaultPort, err := strconv.Atoi(os.Getenv("PORT")) | |
if err != nil { | |
defaultPort = 8080 | |
} | |
port = flag.Int("port", defaultPort, "port number") | |
} | |
func main() { | |
flag.Parse() | |
fmt.Printf("port: %d\n", *port) | |
} |
This file contains hidden or 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
package main | |
import "flag" | |
import "os" | |
import "strconv" | |
import "fmt" | |
var port = flag.Int("port", 0, "port number") | |
func main() { | |
flag.Parse() | |
if *port == 0 { | |
envPort, err := strconv.Atoi(os.Getenv("PORT")) | |
if err != nil { | |
*port = 8080 | |
} else { | |
*port = envPort | |
} | |
} | |
fmt.Printf("port: %d\n", *port) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment