github.com/sagernet/sing-box@v1.9.0-rc.20/experimental/clashapi/profile.go (about) 1 package clashapi 2 3 import ( 4 "net/http" 5 6 "github.com/go-chi/chi/v5" 7 "github.com/go-chi/render" 8 ) 9 10 func profileRouter() http.Handler { 11 r := chi.NewRouter() 12 r.Get("/tracing", subscribeTracing) 13 return r 14 } 15 16 func subscribeTracing(w http.ResponseWriter, r *http.Request) { 17 // if !profile.Tracing.Load() { 18 render.Status(r, http.StatusNotFound) 19 render.JSON(w, r, ErrNotFound) 20 //return 21 //} 22 23 /*wsConn, err := upgrader.Upgrade(w, r, nil) 24 if err != nil { 25 return 26 } 27 28 ch := make(chan map[string]any, 1024) 29 sub := event.Subscribe() 30 defer event.UnSubscribe(sub) 31 buf := &bytes.Buffer{} 32 33 go func() { 34 for elm := range sub { 35 select { 36 case ch <- elm: 37 default: 38 } 39 } 40 close(ch) 41 }() 42 43 for elm := range ch { 44 buf.Reset() 45 if err := json.NewEncoder(buf).Encode(elm); err != nil { 46 break 47 } 48 49 if err := wsConn.WriteMessage(websocket.TextMessage, buf.Bytes()); err != nil { 50 break 51 } 52 }*/ 53 }