github.com/xmidt-org/webpa-common@v1.11.9/xhttp/constant.go (about) 1 package xhttp 2 3 import "net/http" 4 5 // Constant represents an http.Handler that writes prebuilt, constant information to the response writer. 6 type Constant struct { 7 Code int 8 Header http.Header 9 Body []byte 10 } 11 12 // ServeHTTP simply writes the configured information out to the response. 13 func (c Constant) ServeHTTP(response http.ResponseWriter, _ *http.Request) { 14 for k, values := range c.Header { 15 for _, v := range values { 16 response.Header().Add(k, v) 17 } 18 } 19 20 response.WriteHeader(c.Code) 21 if len(c.Body) > 0 { 22 response.Write(c.Body) 23 } 24 }