Skip to content

Instantly share code, notes, and snippets.

@soheilhy
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soheilhy/7f7b328dc7e5179a2c78 to your computer and use it in GitHub Desktop.
Save soheilhy/7f7b328dc7e5179a2c78 to your computer and use it in GitHub Desktop.
args example
package main
import (
"fmt"
"github.com/soheilhy/args"
)
var ListenOn = args.NewInt(args.Default(8080))
var BufferSize = args.NewUint64(args.Default(uint64(1024 * 1024)))
var StateDir = args.NewString(args.Flag("test.state.dir", "/tmp", "state dir"))
func Server(opts ...args.V) {
port := ListenOn.Get(opts)
bufs := BufferSize.Get(opts)
sdir := StateDir.Get(opts)
fmt.Printf("port=%d buf=%d state=%s\n", port, bufs, sdir)
}
func main() {
Server()
// Prints: port=8080 buf=1048576 state=/tmp
Server(ListenOn(80), BufferSize(2048*1024), StateDir("/tmp2"))
// Prints: port=80 buf=2097152 state=/tmp2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment