(w http.ResponseWriter, r *http.Request)
| 13 | } |
| 14 | |
| 15 | func (s *Service) Start(w http.ResponseWriter, r *http.Request) { |
| 16 | data := &common.Backend{} |
| 17 | |
| 18 | if err := common.ReadProtoBody(r.Body, data); err != nil { |
| 19 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | ip, _, err := net.SplitHostPort(r.RemoteAddr) |
| 24 | if err != nil { |
| 25 | http.Error(w, "unknown ip", http.StatusServiceUnavailable) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | if s.Backend() != nil { |
| 30 | log.Println("New connection from ", ip, " core control access was taken away from previous client.") |
| 31 | s.Disconnect() |
| 32 | } |
| 33 | |
| 34 | if err = s.StartBackend(r.Context(), data); err != nil { |
| 35 | http.Error(w, err.Error(), http.StatusServiceUnavailable) |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | s.Connect(ip, data.GetKeepAlive()) |
| 40 | |
| 41 | common.SendProtoResponse(w, s.BaseInfoResponse()) |
| 42 | } |
| 43 | |
| 44 | func (s *Service) Stop(w http.ResponseWriter, _ *http.Request) { |
| 45 | s.Disconnect() |
nothing calls this directly
no test coverage detected