50 lines
1.5 KiB
Go
Raw Normal View History

2024-04-02 13:23:44 +00:00
package send
2024-03-16 14:22:47 +00:00
import (
"encoding/json"
2024-03-22 14:08:24 +00:00
"git.akyoto.dev/go/web"
2024-03-16 14:22:47 +00:00
)
// CSS sends the body with the content type set to `text/css`.
2024-03-22 14:08:24 +00:00
func CSS(ctx web.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/css")
2024-03-16 14:22:47 +00:00
return ctx.String(body)
}
// CSV sends the body with the content type set to `text/csv`.
2024-03-22 14:08:24 +00:00
func CSV(ctx web.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/csv")
return ctx.String(body)
}
// HTML sends the body with the content type set to `text/html`.
2024-03-22 14:08:24 +00:00
func HTML(ctx web.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/html")
2024-03-16 14:22:47 +00:00
return ctx.String(body)
}
// JS sends the body with the content type set to `text/javascript`.
2024-03-22 14:08:24 +00:00
func JS(ctx web.Context, body string) error {
2024-03-16 14:22:47 +00:00
ctx.Response().SetHeader("Content-Type", "text/javascript")
return ctx.String(body)
}
// JSON encodes the object in JSON format and sends it with the content type set to `application/json`.
2024-03-22 14:08:24 +00:00
func JSON(ctx web.Context, object any) error {
2024-03-16 14:22:47 +00:00
ctx.Response().SetHeader("Content-Type", "application/json")
return json.NewEncoder(ctx.Response()).Encode(object)
}
// Text sends the body with the content type set to `text/plain`.
2024-03-22 14:08:24 +00:00
func Text(ctx web.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/plain")
return ctx.String(body)
}
// XML sends the body with the content type set to `text/xml`.
2024-03-22 14:08:24 +00:00
func XML(ctx web.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/xml")
2024-03-16 14:22:47 +00:00
return ctx.String(body)
}