feat: add RenderHTML, Redirect
This commit is contained in:
parent
df318682fa
commit
be161614fb
16
ctx.go
16
ctx.go
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/loveuer/nf/internal/sse"
|
"github.com/loveuer/nf/internal/sse"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net"
|
"net"
|
||||||
@ -362,6 +363,21 @@ func (c *Ctx) HTML(html string) error {
|
|||||||
return err
|
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) {
|
func (c *Ctx) Write(data []byte) (int, error) {
|
||||||
return c.Writer.Write(data)
|
return c.Writer.Write(data)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user