本文整理汇总了Golang中expvar.Get函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Get函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: statsPageHandler
func statsPageHandler(w http.ResponseWriter, r *http.Request, bctx *BasePageContext) {
ctx := &struct {
*BasePageContext
Stats []*stat
}{
BasePageContext: bctx,
Stats: []*stat{},
}
var stats *expvar.Map
stats = expvar.Get("counters").(*expvar.Map)
servStat := expvar.Get("states").(*expvar.Map)
errors := expvar.Get("errors").(*expvar.Map)
for _, ep := range bctx.Globals.GetEndpoints() {
epname := ep.Name
all := stats.Get(epname)
success := stats.Get(epname + "|pass")
unauth := stats.Get(epname + "|401")
fail := stats.Get(epname + "|403")
status := servStat.Get(epname)
statusSSL := servStat.Get(epname + "|ssl")
err := errors.Get(epname)
errSSL := errors.Get(epname + "|ssl")
ctx.Stats = append(ctx.Stats, &stat{epname, fail, success, unauth, all, status, statusSSL,
err, errSSL})
}
RenderTemplateStd(w, ctx, "stats.tmpl")
}
开发者ID:KarolBedkowski,项目名称:secproxy,代码行数:30,代码来源:stats.go
示例2: GetStatus
func GetStatus(w rest.ResponseWriter, r *rest.Request) {
// b := GetBase(r)
status := make(map[string]string)
status["status"] = "ok"
status["attemptsError"] = expvar.Get("attemptsError").String()
status["attemptsSuccess"] = expvar.Get("attemptsSuccess").String()
w.WriteJson(status)
}
开发者ID:yonglehou,项目名称:hooky,代码行数:8,代码来源:status.go
示例3: TestNew
func TestNew(t *testing.T) {
// Publishes prefix in expvar, panics the second time
assert.Nil(t, expvar.Get("name"))
New("name")
assert.NotNil(t, expvar.Get("name"))
assert.IsType(t, expvar.Get("name"), &expvar.Map{})
assert.Panics(t, func() {
New("name")
})
}
开发者ID:patrickToca,项目名称:xstats,代码行数:10,代码来源:expvar_test.go
示例4: TestPublished
func TestPublished(t *testing.T) {
l, err := Listen("")
if err != nil {
t.Fatal(err)
}
opened := make(chan struct{})
closed := make(chan struct{})
go func() {
for {
conn, err := l.Accept()
opened <- struct{}{}
if err != nil {
t.Fatal(err)
}
go func() {
b := make([]byte, 100)
for {
_, err := conn.Read(b)
if err != nil {
conn.Close()
closed <- struct{}{}
return
}
}
}()
}
}()
addr := l.Addr().String()
for i := 1; i <= 3; i++ {
conn1, err := net.Dial("tcp", addr)
if err != nil {
t.Fatal(err)
}
<-opened
if v := expvar.Get("ConnCount").String(); v != "1" {
t.Errorf("ConnCount: %v, want 1", v)
}
conn1.Close()
<-closed
if v := expvar.Get("ConnCount").String(); v != "0" {
t.Errorf("ConnCount: %v, want 1", v)
}
if v := expvar.Get("ConnAccepted").String(); v != fmt.Sprintf("%d", i) {
t.Errorf("ConnAccepted: %v, want %d", v, i)
}
}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:48,代码来源:counting_listener_test.go
示例5: wsServer
func wsServer(ws *websocket.Conn) {
var buf string
defer func() {
if err := ws.Close(); err != nil {
log.Println("Websocket could not be closed", err.Error())
} else {
log.Println("Websocket closed")
}
}()
//q := ws.Request().URL.Query()
//name := q.Get("name")
stopped := false
ticker := time.Tick(time.Duration(1) * time.Second)
for !stopped {
select {
case <-ticker:
val := expvar.Get(metricsVar)
if val == nil {
buf = ""
} else {
buf = val.String()
}
_, err := ws.Write([]byte(buf))
if err != nil {
log.Printf("Websocket error: %s\n", err.Error())
stopped = true
}
}
}
}
开发者ID:millken,项目名称:kaman,代码行数:31,代码来源:server.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng