package server import ( "net/http" "git.pyer.club/kingecg/gotunnelserver/util" "github.com/gorilla/websocket" ) func (s *Server) HandleAgent(c *websocket.Conn, r *http.Request) { agentSession := NewSession(c) agentSession.Start() authEntity := r.Context().Value("authEntity") if authEntity == nil { agentSession.Close() return } agentSession.Name = authEntity.(*util.AuthEntity).Username s.agentSession[agentSession.Id] = agentSession command := NcmdSession(agentSession.Id) agentSession.Send(command) agentSession.Once("Close", func(p ...interface{}) { delete(s.agentSession, agentSession.Id) }) }