refactored code to use wrapper functions when sending the header with content-type

This commit is contained in:
2025-01-13 20:17:49 +09:00
parent 091d28d52e
commit 0100d615d8
4 changed files with 123 additions and 94 deletions

29
hodu.go
View File

@ -157,3 +157,32 @@ func parse_duration_string(dur string) (time.Duration, error) {
if is_digit_or_period(get_last_rune_of_non_empty_string(tmp)) { tmp = tmp + "s" }
return time.ParseDuration(tmp)
}
func write_json_resp_header(w http.ResponseWriter, status_code int) int {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status_code)
return status_code
}
func write_js_resp_header(w http.ResponseWriter, status_code int) int {
w.Header().Set("Content-Type", "application/javascript")
w.WriteHeader(status_code)
return status_code
}
func write_css_resp_header(w http.ResponseWriter, status_code int) int {
w.Header().Set("Content-Type", "text/css")
w.WriteHeader(status_code)
return status_code
}
func write_html_resp_header(w http.ResponseWriter, status_code int) int {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(status_code)
return status_code
}
func write_empty_resp_header(w http.ResponseWriter, status_code int) int {
w.WriteHeader(status_code)
return status_code
}