-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.go
44 lines (34 loc) · 873 Bytes
/
stat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2020 by meng. All rights reserved.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package proxy
import (
"net/http"
"sync"
)
// Stat
// Real Server States
type Stat struct {
// 客户端连接池--
pool sync.Pool
// http
mux *http.ServeMux
}
func (this *Stat) StartStat() {
logger.Info("start stats keep")
// 初始化池子的对象构造
this.pool = sync.Pool{
New: func() interface{} {
return &Context{Request: nil, ResponseWriter: nil}
},
}
this.mux = http.NewServeMux()
// 注册处理函数
this.RegisterRoute("/stats", StatsHandler)
// 监听状态端口
_ = http.ListenAndServe(config.Stats, this.mux)
}
// 注册路由处理函数
func (this *Stat) RegisterRoute(uri string, f func(w http.ResponseWriter, r *http.Request)) {
this.mux.HandleFunc(uri, f)
}