response file
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
kekskurse 2024-09-13 22:33:57 +02:00
parent b80633c7b7
commit 37fe2268c9

21
main.go
View file

@ -18,6 +18,7 @@ type routeConfig struct {
Path string Path string
ResponseHTTPStatus int `yaml:"response_http_status"` ResponseHTTPStatus int `yaml:"response_http_status"`
ResponseBody string `yaml:"response_body"` ResponseBody string `yaml:"response_body"`
ResponseFile string `yaml:"response_file"`
ResponseHeaders map[string]string `yaml:"response_header"` ResponseHeaders map[string]string `yaml:"response_header"`
} }
@ -35,9 +36,23 @@ func (ro routeConfig) httpHandler(w http.ResponseWriter, r *http.Request) {
for v := range ro.ResponseHeaders { for v := range ro.ResponseHeaders {
w.Header().Add(v, ro.ResponseHeaders[v]) w.Header().Add(v, ro.ResponseHeaders[v])
} }
_, err := w.Write([]byte(ro.ResponseBody)) if ro.ResponseBody != "" {
if err != nil { _, err := w.Write([]byte(ro.ResponseBody))
log.Error().Err(err).Msg("cant write body to response writer") if err != nil {
log.Error().Err(err).Msg("cant write body to response writer")
}
}
if ro.ResponseFile != "" {
content, err := os.ReadFile(os.ResponseFile)
if err != nil {
log.Error().Err(err).Msg("cant read response file")
}
_, err = w.Write(content)
if err != nil {
log.Error().Err(err).Msg("cant write body to response writer")
}
} }
rde := requestData{ rde := requestData{