-
Notifications
You must be signed in to change notification settings - Fork 0
/
inbounds.go
39 lines (33 loc) · 860 Bytes
/
inbounds.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
package route
import (
"net/http"
C "github.com/zhaofenghao/clash_go/constant"
"github.com/zhaofenghao/clash_go/listener"
"github.com/zhaofenghao/clash_go/tunnel"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
)
func inboundRouter() http.Handler {
r := chi.NewRouter()
r.Get("/", getInbounds)
r.Put("/", updateInbounds)
return r
}
func getInbounds(w http.ResponseWriter, r *http.Request) {
inbounds := listener.GetInbounds()
render.JSON(w, r, render.M{
"inbounds": inbounds,
})
}
func updateInbounds(w http.ResponseWriter, r *http.Request) {
var req []C.Inbound
if err := render.DecodeJSON(r.Body, &req); err != nil {
render.Status(r, http.StatusBadRequest)
render.JSON(w, r, ErrBadRequest)
return
}
tcpIn := tunnel.TCPIn()
udpIn := tunnel.UDPIn()
listener.ReCreateListeners(req, tcpIn, udpIn)
render.NoContent(w, r)
}