WithFlag adds a standard flag to the global flag instance that allows configuration of the default socket. Users who call Default() must call this function before flags are parsed, for example in an init() block.

When selecting the default bind string, this function will examine its environment for hints about what port to bind to, selecting the GOJI_BIND environment variable, Einhorn, systemd, the PORT environment variable, and the value of DefaultBind, in order. In most cases, this means that the default behavior of the default socket will be reasonable for use in your circumstance.

WithFlag is referenced in 8 repositories



func WithFlag() {
	s := Sniff()
	if s == "" {
		s = DefaultBind
	flag.StringVar(&bind, "bind", s,
		`Address to bind on. If this value has a colon, as in ":8000" or
		"", it will be treated as a TCP address. If it
		begins with a "/" or a ".", it will be treated as a path to a
		UNIX socket. If it begins with the string "fd@", as in "[email protected]",
		it will be treated as a file descriptor (useful for use with
		systemd, for instance). If it begins with the string "einhorn@",
		as in "[email protected]", the corresponding einhorn socket will be
		used. If an option is not explicitly passed, the implementation
		will automatically select among "[email protected]" (Einhorn), "[email protected]"
		(systemd), and ":8000" (fallback) based on its environment.`)