This is still pulling from our generic district mock, but it's still better than what we had. This also includes adding static content hosting for the bootstrap content on the public domain.
40 lines
979 B
Go
40 lines
979 B
Go
package htmlpage
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// Custom ResponseWriter to track Content-Type
|
|
type customResponseWriter struct {
|
|
http.ResponseWriter
|
|
contentType string
|
|
wroteHeader bool
|
|
}
|
|
|
|
func (crw *customResponseWriter) WriteHeader(code int) {
|
|
crw.wroteHeader = true
|
|
crw.ResponseWriter.WriteHeader(code)
|
|
}
|
|
|
|
func (crw *customResponseWriter) Header() http.Header {
|
|
return crw.ResponseWriter.Header()
|
|
}
|
|
|
|
func (crw *customResponseWriter) Write(b []byte) (int, error) {
|
|
if !crw.wroteHeader {
|
|
if crw.contentType == "" {
|
|
crw.contentType = http.DetectContentType(b)
|
|
crw.ResponseWriter.Header().Set("Content-Type", crw.contentType)
|
|
}
|
|
crw.WriteHeader(http.StatusOK)
|
|
}
|
|
return crw.ResponseWriter.Write(b)
|
|
}
|
|
|
|
// Respond with an error that is visible to the user
|
|
func respondError(w http.ResponseWriter, m string, e error, s int) {
|
|
log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error")
|
|
http.Error(w, m, s)
|
|
}
|