feat: add RenderHTML, Redirect
This commit is contained in:
parent
df318682fa
commit
1e66a221e0
16
ctx.go
16
ctx.go
@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/loveuer/nf/internal/sse"
|
||||
"html/template"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net"
|
||||
@ -362,6 +363,21 @@ func (c *Ctx) HTML(html string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Ctx) RenderHTML(name, html string, obj any) error {
|
||||
c.SetHeader("Content-Type", "text/html")
|
||||
t, err := template.New(name).Parse(html)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return t.Execute(c.Writer, obj)
|
||||
}
|
||||
|
||||
func (c *Ctx) Redirect(url string, code int) error {
|
||||
http.Redirect(c.Writer, c.Request, url, code)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Ctx) Write(data []byte) (int, error) {
|
||||
return c.Writer.Write(data)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user