2024-03-20 20:17:23 +00:00
|
|
|
package content
|
2024-03-16 14:22:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"git.akyoto.dev/go/server"
|
|
|
|
)
|
|
|
|
|
2024-03-16 15:55:53 +00:00
|
|
|
// CSS sends the body with the content type set to `text/css`.
|
|
|
|
func CSS(ctx server.Context, body string) error {
|
|
|
|
ctx.Response().SetHeader("Content-Type", "text/css")
|
2024-03-16 14:22:47 +00:00
|
|
|
return ctx.String(body)
|
|
|
|
}
|
|
|
|
|
2024-03-16 15:55:53 +00:00
|
|
|
// CSV sends the body with the content type set to `text/csv`.
|
|
|
|
func CSV(ctx server.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`.
|
|
|
|
func HTML(ctx server.Context, body string) error {
|
|
|
|
ctx.Response().SetHeader("Content-Type", "text/html")
|
2024-03-16 14:22:47 +00:00
|
|
|
return ctx.String(body)
|
|
|
|
}
|
|
|
|
|
2024-03-16 15:55:53 +00:00
|
|
|
// JS sends the body with the content type set to `text/javascript`.
|
2024-03-16 14:22:47 +00:00
|
|
|
func JS(ctx server.Context, body string) error {
|
|
|
|
ctx.Response().SetHeader("Content-Type", "text/javascript")
|
|
|
|
return ctx.String(body)
|
|
|
|
}
|
|
|
|
|
2024-03-16 15:55:53 +00:00
|
|
|
// JSON encodes the object in JSON format and sends it with the content type set to `application/json`.
|
2024-03-16 14:22:47 +00:00
|
|
|
func JSON(ctx server.Context, object any) error {
|
|
|
|
ctx.Response().SetHeader("Content-Type", "application/json")
|
|
|
|
return json.NewEncoder(ctx.Response()).Encode(object)
|
|
|
|
}
|
|
|
|
|
2024-03-16 15:55:53 +00:00
|
|
|
// Text sends the body with the content type set to `text/plain`.
|
|
|
|
func Text(ctx server.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`.
|
|
|
|
func XML(ctx server.Context, body string) error {
|
|
|
|
ctx.Response().SetHeader("Content-Type", "text/xml")
|
2024-03-16 14:22:47 +00:00
|
|
|
return ctx.String(body)
|
|
|
|
}
|