本文整理汇总了Golang中flag.Duration函数的典型用法代码示例。如果您正苦于以下问题:Golang Duration函数的具体用法?Golang Duration怎么用?Golang Duration使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Duration函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
    var (
        defaultProbes = fmt.Sprintf("localhost:%d", xfer.ProbePort)
        probes        = flag.String("probes", defaultProbes, "list of probe endpoints, comma separated")
        batch         = flag.Duration("batch", 1*time.Second, "batch interval")
        window        = flag.Duration("window", 15*time.Second, "window")
        listen        = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
    )
    flag.Parse()

    xfer.MaxBackoff = 10 * time.Second
    c := xfer.NewCollector(*batch, "id")
    for _, addr := range strings.Split(*probes, ",") {
        c.Add(addr)
    }
    defer c.Stop()
    lifo := NewReportLIFO(c, *window)
    defer lifo.Stop()

    http.Handle("/svg", handleSVG(lifo))
    http.Handle("/txt", handleTXT(lifo))
    http.Handle("/", http.HandlerFunc(handleHTML))

    irq := interrupt()
    go func() {
        log.Printf("listening on %s", *listen)
        log.Print(http.ListenAndServe(*listen, nil))
        irq <- syscall.SIGINT
    }()
    <-irq
    log.Printf("shutting down")
}

开发者ID:neviim,项目名称:scope,代码行数:32,代码来源:main.go

示例2: decodeRefArg

func decodeRefArg(name, typeName string) (interface{}, error) {
    switch strings.ToLower(typeName) {
    case "*bool":
        newValue := flag.Bool(name, app.DefaultBoolValue, name)
        return newValue, nil
    case "bool":
        newValue := flag.Bool(name, app.DefaultBoolValue, name)
        return *newValue, nil

    case "*string":
        newValue := flag.String(name, app.DefaultStringValue, name)
        return *newValue, nil
    case "string":
        newValue := flag.String(name, app.DefaultStringValue, name)
        return *newValue, nil

    case "*time.duration":
        newValue := flag.Duration(name, app.DefaultDurationValue, name)
        return *newValue, nil
    case "time.duration":
        newValue := flag.Duration(name, app.DefaultDurationValue, name)
        return *newValue, nil

    case "*float64":
        newValue := flag.Float64(name, app.DefaultFloat64Value, name)
        return *newValue, nil
    case "float64":
        newValue := flag.Float64(name, app.DefaultFloat64Value, name)
        return *newValue, nil

    case "*int":
        newValue := flag.Int(name, app.DefaultIntValue, name)
        return *newValue, nil
    case "int":
        newValue := flag.Int(name, app.DefaultIntValue, name)
        return *newValue, nil

    case "*int64":
        newValue := flag.Int64(name, app.DefaultInt64Value, name)
        return *newValue, nil
    case "int64":
        newValue := flag.Int64(name, app.DefaultInt64Value, name)
        return *newValue, nil

    case "*uint":
        newValue := flag.Uint(name, app.DefaultUIntValue, name)
        return *newValue, nil
    case "uint":
        newValue := flag.Uint(name, app.DefaultUIntValue, name)
        return *newValue, nil

    case "*uint64":
        newValue := flag.Uint64(name, app.DefaultUInt64Value, name)
        return *newValue, nil
    case "uint64":
        newValue := flag.Uint64(name, app.DefaultUInt64Value, name)
        return *newValue, nil
    }
    return nil, fmt.Errorf("unknow type %s for argument %s", typeName, name)
}

开发者ID:goatcms,项目名称:goat-core,代码行数:60,代码来源:injector.go

示例3: main

func main() {
    pg := flag.Bool("pg", false, "Check PostgreSQL TLS, incompatible with -hostfile")
    timeout := flag.Duration("timeout", 5*time.Second, "Timeout after sending heartbeat")
    hostFile := flag.String("hostfile", "", "Path to a newline seperated file with hosts or ips")
    workers := flag.Int("workers", runtime.NumCPU()*10, "Number of workers to scan hosts with, only used with hostfile flag")
    retryDelay := flag.Duration("retry", 10*time.Second, "Seconds to wait before retesting a host after an unfavorable response")
    refreshDelay := flag.Duration("refresh", 10*time.Minute, "Seconds to wait before rechecking secure hosts")
    listen := flag.String("listen", "localhost:5000", "Address to serve HTTP dashboard from")
    flag.Usage = func() {
        fmt.Fprintf(os.Stderr, "Usage: %s [options] host[:443]\n", os.Args[0])
        fmt.Fprintf(os.Stderr, "Options:\n")
        flag.PrintDefaults()
    }
    flag.Parse()

    if *hostFile != "" {
        checkMultiHosts(*hostFile, *timeout, *retryDelay, *refreshDelay, *workers, *listen)
    } else {
        if flag.NArg() != 1 {
            flag.Usage()
            os.Exit(2)
        }
        checkSingleHost(flag.Arg(0), *timeout, *pg)
    }
}

开发者ID:rossdylan,项目名称:heartbleeder,代码行数:25,代码来源:heartbleeder.go

示例4: init

func init() {
    //Command line variables
    mqttServer = flag.String("s", ":1883", "IP and Port of the MQTT Broker. e.g. 127.0.0.1:1883. Default: :1883")
    stationID = flag.String("u", "", "WU PWS station id")
    password = flag.String("p", "", "WU PWS station password")
    software = flag.String("f", "gowupws", "Name of the software updating the PWS. Default: gowupws")
    calculateDewpoint = flag.Bool("d", false, "Provide calculated dewpoint, if not provided as a parameter. Default: False")
    configPath = flag.String("c", "", "Provide path to config file")
    sensorExpire = flag.Duration("l", 5*time.Minute, "Sensor/Device life, minutes")
    checkCache = flag.Duration("e", 1*time.Minute, "Check sensor/device every, minutes")
    stationReportPeriod = flag.Duration("r", 2*time.Minute, "Station report period, minutes")
    flag.Parse()

    if *stationID == "" {
        log.Fatal("A Weather Underground station ID has to be provided")
    }

    if *password == "" {
        log.Fatal("A Weather Underground password has to be provided")
    }

    if *configPath == "" {
        log.Fatal("A config file has to be provided")
    }

    config = readConfigFile(*configPath)
    addressParameter = mapAddressToParameter(&config)

    done = make(chan struct{})
}

开发者ID:danward79,项目名称:wuMQTTAgregate,代码行数:30,代码来源:main.go

示例5: main

func main() {
    flag.Usage = func() {
        fmt.Fprintf(os.Stderr, "usage: %s [flags] <destination>\n", os.Args[0])
        flag.PrintDefaults()
    }
    interval := flag.Duration("interval", time.Second*1, "ping packet retransmission interval")
    timeout := flag.Duration("timeout", time.Second*5, "ping timeout until failure")
    flag.Parse()
    if flag.NArg() != 1 {
        flag.Usage()
        os.Exit(1)
    }

    server := flag.Arg(0)

    host, port, err := net.SplitHostPort(server)
    if err != nil {
        host = server
        port = strconv.Itoa(gumble.DefaultPort)
    }

    resp, err := gumble.Ping(net.JoinHostPort(host, port), *interval, *timeout)
    if err != nil {
        fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
        os.Exit(1)
    }
    major, minor, patch := resp.Version.SemanticVersion()
    fmt.Printf("Address:         %s\n", resp.Address)
    fmt.Printf("Ping:            %s\n", resp.Ping)
    fmt.Printf("Version:         %d.%d.%d\n", major, minor, patch)
    fmt.Printf("Connected Users: %d\n", resp.ConnectedUsers)
    fmt.Printf("Maximum Users:   %d\n", resp.MaximumUsers)
    fmt.Printf("Maximum Bitrate: %d\n", resp.MaximumBitrate)
}

开发者ID:matthieugrieger,项目名称:mumbledj,代码行数:34,代码来源:main.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng