(w http.ResponseWriter, r *http.Request)
| 206 | } |
| 207 | |
| 208 | func (st *state) getState(w http.ResponseWriter, r *http.Request) { |
| 209 | x.AddCorsHeaders(w) |
| 210 | w.Header().Set("Content-Type", "application/json") |
| 211 | |
| 212 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 213 | defer cancel() |
| 214 | if err := st.node.WaitLinearizableRead(ctx); err != nil { |
| 215 | w.WriteHeader(http.StatusInternalServerError) |
| 216 | x.SetStatus(w, x.Error, err.Error()) |
| 217 | return |
| 218 | } |
| 219 | mstate := st.zero.membershipState() |
| 220 | if mstate == nil { |
| 221 | x.SetStatus(w, x.ErrorNoData, "No membership state found.") |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | m := protojson.MarshalOptions{EmitUnpopulated: true} |
| 226 | buf, err := m.Marshal(mstate) |
| 227 | if err != nil { |
| 228 | x.SetStatus(w, x.ErrorNoData, err.Error()) |
| 229 | return |
| 230 | } |
| 231 | if _, err := w.Write(buf); err != nil { |
| 232 | x.SetStatus(w, x.Error, err.Error()) |
| 233 | return |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | func (s *Server) zeroHealth(ctx context.Context) (*api.Response, error) { |
| 238 | if ctx.Err() != nil { |
nothing calls this directly
no test coverage detected