Created
February 6, 2015 21:06
-
-
Save ian-kent/c419db3ef74426b69067 to your computer and use it in GitHub Desktop.
My new favourite golang config pattern
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 config | |
import "flag" | |
var BindAddress string | |
var SMTPHost string | |
var SMTPPort int | |
func Configure() { | |
flag.StringVar(&BindAddress, "bind", ":9650", "Bind address") | |
flag.StringVar(&SMTPHost, "smtp-host", "localhost", "SMTP server host") | |
flag.IntVar(&SMTPPort, "smtp-port", 587, "SMTP server port") | |
flag.Parse() | |
} | |
var _ = func() { Configure() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not just rename Configure() to init() which eliminates the need for the 'var _' declaration?
Using an unbound variable declaration to invoke a function for it's side-effects is esoteric, at best.