-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
profile.go
53 lines (44 loc) · 907 Bytes
/
profile.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
45
46
47
48
49
50
51
52
53
package clashapi
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
)
func profileRouter() http.Handler {
r := chi.NewRouter()
r.Get("/tracing", subscribeTracing)
return r
}
func subscribeTracing(w http.ResponseWriter, r *http.Request) {
// if !profile.Tracing.Load() {
render.Status(r, http.StatusNotFound)
render.JSON(w, r, ErrNotFound)
//return
//}
/*wsConn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
ch := make(chan map[string]any, 1024)
sub := event.Subscribe()
defer event.UnSubscribe(sub)
buf := &bytes.Buffer{}
go func() {
for elm := range sub {
select {
case ch <- elm:
default:
}
}
close(ch)
}()
for elm := range ch {
buf.Reset()
if err := json.NewEncoder(buf).Encode(elm); err != nil {
break
}
if err := wsConn.WriteMessage(websocket.TextMessage, buf.Bytes()); err != nil {
break
}
}*/
}