nidus-sync/rmo/scss.go
Eli Ribble 0ec810591e
lint: fix errcheck for Close and Write calls across multiple files
Use lint.LogOnErr for deferred Body/File/Client Close calls.
Use lint.Write for unchecked w.Write calls.
Fix bug in sync/sms.go where fmt.Errorf result was discarded
(replace with proper log.Error call).
2026-05-09 02:29:07 +00:00

42 lines
1.2 KiB
Go

package rmo
import (
"fmt"
"io"
"net/http"
"os"
"github.com/Gleipnir-Technology/nidus-sync/lint"
"github.com/gorilla/mux"
"github.com/rs/zerolog/log"
)
func getScssDebug(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
path := vars["*"]
full_path := "scss/" + path
//log.Debug().Str("path", path).Str("full_path", full_path).Msg("working on SCSS debug")
file, err := os.Open(full_path)
if err != nil {
respondError(w, "failed to open file", err, http.StatusInternalServerError)
return
}
defer lint.LogOnErr(file.Close, "close scss file")
fileInfo, err := file.Stat()
if err != nil {
respondError(w, "failed to stat file", err, http.StatusInternalServerError)
return
}
// Set appropriate headers
w.Header().Set("Content-Type", "text/scss")
w.Header().Set("Content-Length", fmt.Sprintf("%d", fileInfo.Size()))
// Copy file contents to response writer
_, err = io.Copy(w, file)
if err != nil {
// Note: At this point, we've already started writing the response,
// so we can't change the status code anymore. The best we can do
// is log the error and abandon the connection.
log.Warn().Str("path", path).Msg("Failed to write scss file to output")
}
}