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

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

示例1: pushMetric

// pushMetric adds the metric to the end of the list and returns a comma separated string of the
// previous 61 entries.  We return 61 instead of 60 (an hour) because the chart on the client
// tracks deltas between these values - there is nothing to compare the first value against.
func pushMetric(history *list.List, ev expvar.Var) string {
    history.PushBack(ev.String())
    if history.Len() > 61 {
        history.Remove(history.Front())
    }
    return JoinStringList(history)
}

开发者ID:barbourkd,项目名称:inbucket,代码行数:10,代码来源:listener.go

示例2: SetRate

func SetRate(m Map, key string, value expvar.Var, timeframe, unit time.Duration) {
    if value != nil {
        v, _ := strconv.ParseInt(value.String(), 10, 64)
        m.Set(key, newRate(v, timeframe, unit))
    } else {
        m.Set(key, zeroValue)
    }
}

开发者ID:smancke,项目名称:guble,代码行数:8,代码来源:map.go

示例3: SetAverage

func SetAverage(m Map, key string, totalVar, casesVar expvar.Var, scale int64, defaultValue string) {
    if totalVar != nil && casesVar != nil {
        total, _ := strconv.ParseInt(totalVar.String(), 10, 64)
        cases, _ := strconv.ParseInt(casesVar.String(), 10, 64)
        m.Set(key, newAverage(total, cases, scale, defaultValue))
    } else {
        m.Set(key, zeroValue)
    }
}

开发者ID:smancke,项目名称:guble,代码行数:9,代码来源:map.go

示例4: statToValue

// statToValue converts from a stats.Stat type to a JSON representable value.
// This is preferred to just calling the String() for things like numbers, so that
// InfluxDB can also represent the metrics as numbers.
// TODO(aaijazi): this needs to be extended to support better serialization of other types..
// It's probably good to do this after InfluxDB 0.9 is released, as it has has better support
// for arbitrary dict values (as tags).
func statToValue(v expvar.Var) interface{} {
    switch v := v.(type) {
    case *stats.Float:
        return v.Get()
    case *stats.Int:
        return v.Get()
    case stats.FloatFunc:
        return v()
    case stats.IntFunc:
        return v()
    default:
        return v.String()
    }
}

开发者ID:CowLeo,项目名称:vitess,代码行数:20,代码来源:influxdb_backend.go

示例5: TestDHTLarge

// Requires Internet access and can be flaky if the server or the internet is
// slow.
func TestDHTLarge(t *testing.T) {
    if testing.Short() {
        t.Skip("TestDHTLarge requires internet access and can be flaky. Skipping in short mode.")
    }
    defer stats(t)
    c := NewConfig()
    c.SaveRoutingTable = false
    node, err := New(c)
    if err != nil {
        t.Fatalf("dht New: %v", err)
    }
    if err = node.Start(); err != nil {
        t.Fatalf("node.Run: %v", err)
    }
    realDHTNodes := []string{
        "1.a.magnets.im",
        "router.utorrent.com",
    }
    for _, addr := range realDHTNodes {
        ip, err := net.LookupHost(addr)
        if err != nil {
            t.Error(err)
            continue
        }
        node.AddNode(ip[0] + ":6881")
    }

    // Test that we can reach at least one node.
    success := false
    var (
        reachable int
        v         expvar.Var
    )
    for i := 0; i < 10; i++ {
        v = expvar.Get("totalNodesReached")
        reachable, err = strconv.Atoi(v.String())
        if err != nil {
            t.Errorf("totalNodesReached conversion to int failed: %v", err)
            continue
        }
        if reachable > 0 {
            t.Logf("Contacted %d DHT nodes.", reachable)
            success = true
            break
        }
        time.Sleep(time.Second)
    }
    if !success {
        t.Fatal("No external DHT node could be contacted.")
    }

    // Test that we can find peers for a known torrent in a timely fashion.
    //
    // Torrent from: http://www.clearbits.net/torrents/244-time-management-for-anarchists-1
    infoHash := InfoHash("\xb4\x62\xc0\xa8\xbc\xef\x1c\xe5\xbb\x56\xb9\xfd\xb8\xcf\x37\xff\xd0\x2f\x5f\x59")
    go node.PeersRequest(string(infoHash), true)
    var infoHashPeers map[InfoHash][]string
    select {
    case infoHashPeers = <-node.PeersRequestResults:
        t.Logf("Found %d peers.", len(infoHashPeers[infoHash]))
    case <-time.Tick(10 * time.Second):
        t.Fatal("Could not find new peers: timed out")
    }
    for ih, peers := range infoHashPeers {
        if infoHash != ih {
            t.Fatal("Unexpected infohash returned")
        }
        if len(peers) == 0 {
            t.Fatal("Could not find new torrent peers.")
        }
        for _, peer := range peers {
            t.Logf("peer found: %v", nettools.BinaryToDottedPort(peer))
        }
    }
}

开发者ID:peterlee2008,项目名称:dht,代码行数:77,代码来源:dht_test.go

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