@@ -329,15 +329,21 @@ func (el *AwaitElection) startStatusEndpoint(ctx context.Context) {
329329 serveMux .HandleFunc ("/" , func (writer http.ResponseWriter , request * http.Request ) {
330330 resp , err := el .EtcdClient .Get (ctx , el .LockName )
331331 if err != nil || len (resp .Kvs ) == 0 {
332- writer .Write ([]byte ("{\" status\" : \" ok\" , \" phase\" : \" awaiting\" }\n " ))
332+ writer .Header ().Set ("Content-Type" , "text/plain" )
333+ writer .WriteHeader (http .StatusOK )
334+ writer .Write ([]byte (fmt .Sprintf ("{\" status\" : \" ok\" , \" phase\" : \" awaiting\" , \" leader\" : \" unknown\" }\n " )))
333335 return
334336 }
335- if string (resp .Kvs [0 ].Value ) == el .LeaderIdentity {
337+
338+ currentLeader := string (resp .Kvs [0 ].Value )
339+ if currentLeader == el .LeaderIdentity {
336340 writer .Header ().Set ("Content-Type" , "application/json" )
337341 writer .WriteHeader (http .StatusOK )
338- writer .Write ([]byte ("{\" status\" : \" ok\" , \" phase\" : \" running\" }\n " ))
342+ writer .Write ([]byte (fmt . Sprintf ( "{\" status\" : \" ok\" , \" phase\" : \" running\" , \" leader \" : \" %s \" }\n " , currentLeader ) ))
339343 } else {
340- writer .Write ([]byte ("{\" status\" : \" ok\" , \" phase\" : \" awaiting\" }\n " ))
344+ writer .Header ().Set ("Content-Type" , "application/json" )
345+ writer .WriteHeader (http .StatusOK )
346+ writer .Write ([]byte (fmt .Sprintf ("{\" status\" : \" ok\" , \" phase\" : \" awaiting\" , \" leader\" : \" %s\" }\n " , currentLeader )))
341347 }
342348 })
343349
0 commit comments