Total Lines | 36 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package main |
||
2 | |||
3 | import ( |
||
4 | "net/http" |
||
5 | |||
6 | "github.com/a-h/templ" |
||
7 | "github.com/labstack/echo/v4" |
||
8 | "github.com/memnix/memnix-rest/app/v2/views" |
||
9 | ) |
||
10 | |||
11 | func main() { |
||
12 | e := echo.New() |
||
13 | component := views.Page("John") |
||
14 | |||
15 | clickedComponent := views.Clicked() |
||
16 | |||
17 | e.Static("/", "static") |
||
18 | |||
19 | e.GET("/", func(c echo.Context) error { |
||
20 | err := component.Render(c.Request().Context(), c.Response()) |
||
21 | if err != nil { |
||
22 | return err |
||
23 | } |
||
24 | return nil |
||
25 | }) |
||
26 | |||
27 | e.POST("/clicked", func(c echo.Context) error { |
||
28 | return Render(c, http.StatusOK, clickedComponent) |
||
29 | }) |
||
30 | |||
31 | e.Logger.Fatal(e.Start(":3000")) |
||
32 | } |
||
33 | |||
34 | func Render(c echo.Context, _ int, t templ.Component) error { |
||
35 | c.Response().Writer.Header().Set(echo.HeaderContentType, echo.MIMETextHTML) |
||
36 | return t.Render(c.Request().Context(), c.Response()) |
||
37 | } |
||
38 |