Fix embedded static files on production builds
This commit is contained in:
parent
9cbce4ff14
commit
a2c3f52ab4
12 changed files with 209 additions and 3083 deletions
|
|
@ -6,33 +6,6 @@ import (
|
|||
"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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue