github.com/grailbio/base@v0.0.11/status/http.go (about)

     1  // Copyright 2018 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package status
     6  
     7  import (
     8  	"net/http"
     9  )
    10  
    11  type statusHandler struct{ *Status }
    12  
    13  // Handler returns a HTTP handler that renders a simple plain-text status
    14  // snapshot of s on each request.
    15  func Handler(s *Status) http.Handler {
    16  	return statusHandler{s}
    17  }
    18  
    19  func (h statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    20  	w.Header().Set("Content-Type", "text/plain")
    21  	// If writing fails, there's not much we can do.
    22  	_ = h.Status.Marshal(w)
    23  }