本文整理汇总了Golang中flag.PrintDefaults函数的典型用法代码示例。如果您正苦于以下问题:Golang PrintDefaults函数的具体用法?Golang PrintDefaults怎么用?Golang PrintDefaults使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrintDefaults函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
certpath := flag.String("cert", "", "The path to a PEM certificate")
keypath := flag.String("key", "", "The path to a PEM key")
flag.Parse()
if len(*certpath) == 0 || len(*keypath) == 0 {
flag.PrintDefaults()
return
}
ctx := gossl.NewContext(gossl.SSLv3Method())
ctx.SetOptions(gossl.OpNoCompression)
err := ctx.UsePrivateKeyFile(*keypath, gossl.FileTypePem)
if err != nil {
panic(err)
}
ctx.UseCertificateFile(*certpath, gossl.FileTypePem)
if err != nil {
panic(err)
}
l, err := net.Listen("tcp", ":8000")
if err != nil {
panic(err)
}
l, err = gossl.NewListener(l, ctx)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path))
})
http.Serve(l, nil)
}
示例2: main
func main() {
detector := flag.Bool("detector", false, "start detector")
// webapp := flag.Bool("webapp", false, "start webapp")
// alerter := flag.Bool("alerter", false, "start alerter")
fileName := flag.String("config", "", "config path")
version := flag.Bool("version", false, "show version")
flag.Parse()
if *version {
fmt.Fprintln(os.Stderr, VERSION)
os.Exit(1)
}
if flag.NFlag() != 2 {
flag.PrintDefaults()
os.Exit(1)
}
cfg, err := config.NewWithJsonFile(*fileName)
if err != nil {
log.Fatalf("failed to read %s: %v", *fileName, err)
}
switch {
case *detector:
StartDetector(cfg.Detector)
default:
flag.PrintDefaults()
os.Exit(1)
}
}
示例3: init
func init() {
flag.StringVar(&address, "address", "localhost:28015", "The address to connect to a RethinkDB instance.")
flag.StringVar(&db, "database", "", "The RethinkDB database to use.")
flag.StringVar(&table, "table", "", "The RethinkDB database table to use.")
flag.Parse()
if len(db) == 0 {
fmt.Println("You must pass the name of a database to use.\n")
flag.PrintDefaults()
os.Exit(1)
}
if len(table) == 0 {
fmt.Println("You must pass the name of database table to use.\n")
flag.PrintDefaults()
os.Exit(1)
}
//session, err := r.Connect(r.ConnectOpts{
// Address: address,
// Database: db,
// MaxIdle: 10,
// MaxOpen: 10,
//})
//if err != nil {
// log.Fatalln(err.Error())
//}
}
示例4: main
func main() {
flag.Parse()
if len(config_file) > 0 {
config = NewTunnelConfig(config_file)
info.Println(config)
}
argv := flag.Args()
argc := len(argv)
mode := ""
if argc > 0 {
mode = argv[argc-1]
}
go NewStatServer().serve()
appevt.Trigger("appmode", mode)
switch mode {
case "client":
if config == nil {
flag.PrintDefaults()
os.Exit(-1)
}
tc := NewTunnelc()
tc.serve()
case "server":
td := NewTunneld()
td.serve()
default:
log.Println("Invalid mode")
flag.PrintDefaults()
}
}
示例5: init
func init() {
flag.StringVar(&sourceURL, "u", "", "the url you wish to download from")
flag.StringVar(&remoteFile, "r", "", "the remote filename to download")
flag.StringVar(&localFile, "o", "", "the output filename")
flag.IntVar(&timeout, "t", 5, "timeout, in seconds")
flag.BoolVar(&verbose, "v", false, "verbose")
flag.BoolVar(&showFiles, "l", false, "list files in zip")
flag.Uint64Var(&limitBytes, "b", 0, "limit filesize downloaded (in bytes)")
flag.Parse()
if sourceURL == "" {
fmt.Println("You must specify a URL")
flag.PrintDefaults()
os.Exit(1)
}
if !showFiles {
if remoteFile == "" {
fmt.Println("You must specify a remote filename")
flag.PrintDefaults()
os.Exit(1)
}
if localFile == "" {
_, localFile = filepath.Split(remoteFile)
}
}
}
示例6: Main
/**
* Our main entry point.
* @return{struct} Our config structure populated with configuration info.
*/
func Main() Config {
config := Config{}
flag.IntVar(&config.Num_messages, "num-messages", 1,
"How many messages to send?")
flag.IntVar(&config.Message_size, "message-size", 1,
"How many bytes in each message?")
flag.IntVar(&config.Num_cores, "num-cores", 1,
"How many cores to use? (Max:"+strconv.Itoa(runtime.NumCPU())+")")
flag.IntVar(&config.Buffer_size, "buffer-size", 0,
"Buffer size for our channel?")
flag.IntVar(&config.Num_goroutines, "num-goroutines", 1,
"How many goroutines to run?")
flag.IntVar(&config.Num_goroutine_work, "num-goroutine-work", 1,
"How much work to do in each goroutine?")
var h = flag.Bool("h", false, "Print this help")
var help = flag.Bool("help", false, "Print this help")
flag.Parse()
if *h || *help {
flag.PrintDefaults()
panic("Bailing out due to asking for help")
} else if config.Num_goroutine_work < 1 {
flag.PrintDefaults()
panic("Goroutine work must be >= 1")
}
return (config)
} // End of Main()
示例7: main
func main() {
flag.Parse()
block, err := hex.DecodeString(*hexBlock)
if err != nil {
log.Println(err)
flag.PrintDefaults()
return
} else if len(block) != 16 {
log.Println("Block must be 128 bits.")
flag.PrintDefaults()
return
}
// Read construction from disk and parse it into something usable.
data, err := ioutil.ReadFile("./constr.txt")
if err != nil {
log.Fatal(err)
}
constr, err := full.Parse(data)
if err != nil {
log.Fatal(err)
}
// Encrypt block in-place, and print as hex.
constr.Encrypt(block, block)
fmt.Printf("%x\n", block)
}
示例8: main
func main() {
flag.Float64Var(&samplingProbability, "p", 0.0, "Sample lines at probability p in [0, 1].")
flag.UintVar(&reservoirSize, "r", 0, "Sample exactly k lines.")
flag.StringVar(&splitStr, "s", "", "Split the input into n random subsets. Delimit weights with commas, e.g. 8,1,1. Weights will be normalized to sum to 1.")
flag.StringVar(&outputFilename, "o", "", "Output file(s). If not specified, write to stdout. Required and used as a basename for splitting. The basename will be appended with _1, _2, etc.")
flag.Parse()
rand.Seed(time.Now().UnixNano())
if reservoirSize > 0 && samplingProbability > 0.0 {
fmt.Println("You can specify either -p or -r, but not both.")
flag.PrintDefaults()
return
}
input := inputReader(flag.Args())
if splitStr != "" {
if outputFilename == "" {
fmt.Println("To split input, you must specify an output base filename with -o.")
flag.PrintDefaults()
return
}
Split(input)
} else if samplingProbability > 0.0 {
sampleAtRate(input, samplingProbability, os.Stdout)
} else if reservoirSize > 0 {
lines := reservoirSample(input, reservoirSize)
for _, line := range lines {
fmt.Print(line)
}
}
}
示例9: main
func main() {
flag.StringVar(&presently.Dir, "d", "", "Directory of the repository")
flag.StringVar(&presently.DeployDir, "o", "", "Directory of the deployment")
flag.StringVar(&presently.Port, "p", "", "Port to listen")
flag.Parse()
args := flag.Args()
if presently.Dir == "" {
if len(args) == 0 {
fmt.Println("You need to specify -d")
flag.PrintDefaults()
os.Exit(0)
} else {
presently.Dir = args[0]
}
}
if presently.DeployDir == "" {
fmt.Println("You need to specify -o")
flag.PrintDefaults()
os.Exit(0)
}
presently.Deploy()
}
示例10: main
func main() {
// redefine the flags function
flag.Usage = func() {
// print defaults of fatbin only if it's named fatbin
if filepath.Base(os.Args[0]) == "fatbin" {
flag.PrintDefaults()
return
}
}
// read the flags
err := parseFlags()
if err != nil {
fmt.Println(err)
flag.PrintDefaults()
return
}
// compress mode
if len(flags.Directory) > 0 && len(flags.Executable) > 0 {
build()
return
}
run()
}
示例11: main
func main() {
flag.Parse()
if *help {
fmt.Println(useage)
flag.PrintDefaults()
return
}
if *dbname == "" {
fmt.Println(useage)
flag.PrintDefaults()
return
}
if *source == "" {
fmt.Println(useage)
flag.PrintDefaults()
return
}
if *path == "" {
fmt.Println(useage)
flag.PrintDefaults()
return
}
sync := db.CreateSyncDB(*dbname, *source)
sync.SyncDB(*path, *drop, *role)
}
示例12: main
func main() {
flag.Parse()
if *apiKey == "" || *host == "" {
flag.PrintDefaults()
os.Exit(1)
}
if *serviceAccount == "" && *echo == "" {
fmt.Fprint(os.Stderr, "Provide one of -echo or -service-account.")
flag.PrintDefaults()
os.Exit(1)
}
if *serviceAccount != "" && *echo != "" {
fmt.Fprint(os.Stderr, "Provide only one of -echo or -service-account.")
flag.PrintDefaults()
os.Exit(1)
}
var resp *http.Response
var err error
if *echo != "" {
resp, err = doEcho()
} else if *serviceAccount != "" {
resp, err = doJWT()
}
if err != nil {
log.Fatal(err)
}
b, err := httputil.DumpResponse(resp, true)
if err != nil {
log.Fatal(err)
}
os.Stdout.Write(b)
}
示例13: main
func main() {
flag.Parse()
if !flag.Parsed() {
fmt.Fprintf(os.Stderr, "Invalid command line!\n")
flag.PrintDefaults()
return
}
if len(flag.Args()) < 1 {
fmt.Fprintf(os.Stderr, "No file is specified\n")
flag.PrintDefaults()
return
}
filename := flag.Arg(0)
file, err := NewLogFile(filename)
if err != nil {
fmt.Fprintf(os.Stderr, "NewLogFile() failed! %s\n", err)
panic(err)
}
defer file.Close()
err = file.Monitor(*linesToPrint)
if err != nil {
fmt.Fprintf(os.Stderr, "Monitor() failed! %s\n", err)
panic(err)
}
shutdown := make(chan bool)
<-shutdown
}
示例14: main
func main() {
var defaultMaxprocs int
var err error
if defaultMaxprocs, err = strconv.Atoi(os.Getenv("GOMAXPROCS")); err != nil {
defaultMaxprocs = runtime.NumCPU() * 2
}
var mode, dir string
var port, maxprocs int
flag.StringVar(&mode, "mode", "", "[v1|v2|v3|bench|durable-bench|example]")
flag.StringVar(&dir, "dir", "", "database directory")
flag.IntVar(&port, "port", 0, "listening port number")
flag.IntVar(&maxprocs, "gomaxprocs", defaultMaxprocs, "GOMAXPROCS")
flag.Parse()
if mode == "" {
flag.PrintDefaults()
return
}
runtime.GOMAXPROCS(maxprocs)
log.Printf("GOMAXPROCS is set to %d", maxprocs)
if maxprocs < runtime.NumCPU() {
log.Printf("GOMAXPROCS (%d) is less than number of CPUs (%d), this may affect performance. You can change it via environment variable GOMAXPROCS or by passing CLI parameter -gomaxprocs", maxprocs, runtime.NumCPU())
}
switch mode {
case "v1":
fallthrough
case "v2":
fallthrough
case "v3":
if dir == "" {
log.Fatal("Please specify database directory, for example -dir=/tmp/db")
}
if port == 0 {
log.Fatal("Please specify port number, for example -port=8080")
}
db, err := db.OpenDB(dir)
if err != nil {
log.Fatal(err)
}
if mode == "v1" {
v1.Start(db, port)
} else if mode == "v2" {
v2.Start(db, port)
} else if mode == "v3" {
v3.Start(db, port)
}
case "bench":
benchmark()
case "durable-bench":
durableBenchmark()
case "example":
embeddedExample()
default:
flag.PrintDefaults()
return
}
}
示例15: main
func main() {
aspong := flag.Bool("asPong", false, "Starts Pong service")
asping := flag.Bool("asPing", false, "Starts Ping service")
port := flag.Int("port", 8080, "Sets the port")
ponghost := flag.String("pongHost", "localhost", "Host (valid DNS name or IP) of the pong service")
pongport := flag.Int("pongPort", 8080, "Port of the pong service")
flag.Parse()
if *aspong && *asping {
fmt.Println("You can only start ping or pong service, not both with the same command.")
flag.PrintDefaults()
os.Exit(1)
}
if *aspong {
pong.Start(*port)
os.Exit(0)
}
if *asping {
ping.Start(*port, *ponghost, *pongport)
os.Exit(0)
}
flag.PrintDefaults()
}