Improved API
This commit is contained in:
32
send/send.go
Normal file
32
send/send.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user