This commit is contained in:
parent
b80633c7b7
commit
37fe2268c9
1 changed files with 18 additions and 3 deletions
15
main.go
15
main.go
|
@ -18,6 +18,7 @@ type routeConfig struct {
|
|||
Path string
|
||||
ResponseHTTPStatus int `yaml:"response_http_status"`
|
||||
ResponseBody string `yaml:"response_body"`
|
||||
ResponseFile string `yaml:"response_file"`
|
||||
ResponseHeaders map[string]string `yaml:"response_header"`
|
||||
}
|
||||
|
||||
|
@ -35,10 +36,24 @@ func (ro routeConfig) httpHandler(w http.ResponseWriter, r *http.Request) {
|
|||
for v := range ro.ResponseHeaders {
|
||||
w.Header().Add(v, ro.ResponseHeaders[v])
|
||||
}
|
||||
if ro.ResponseBody != "" {
|
||||
_, err := w.Write([]byte(ro.ResponseBody))
|
||||
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{
|
||||
Path: r.URL.Path,
|
||||
|
|
Loading…
Reference in a new issue