Improved API

This commit is contained in:
Eduard Urbach 2024-03-16 15:22:47 +01:00
parent e8f9f4ff95
commit a172cbd45f
Signed by: eduard
GPG key ID: 49226B848C78F6C8
10 changed files with 232 additions and 121 deletions

32
send/send.go Normal file
View file

@ -0,0 +1,32 @@
package send
import (
"encoding/json"
"git.akyoto.dev/go/server"
)
func Text(ctx server.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/plain")
return ctx.String(body)
}
func CSS(ctx server.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/css")
return ctx.String(body)
}
func JS(ctx server.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/javascript")
return ctx.String(body)
}
func JSON(ctx server.Context, object any) error {
ctx.Response().SetHeader("Content-Type", "application/json")
return json.NewEncoder(ctx.Response()).Encode(object)
}
func HTML(ctx server.Context, body string) error {
ctx.Response().SetHeader("Content-Type", "text/html")
return ctx.String(body)
}