Last active
August 29, 2015 14:25
-
-
Save soheilhy/7f7b328dc7e5179a2c78 to your computer and use it in GitHub Desktop.
args example
This file contains 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 ( | |
"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