This commit is contained in:
2023-10-02 17:42:50 +02:00
commit a42c8943fc
19 changed files with 553 additions and 0 deletions

29
server/index.go Normal file
View File

@ -0,0 +1,29 @@
package server
import (
"code.icod.de/dalu/htmxginpongo/model"
"code.icod.de/dalu/htmxginpongo/storage"
"github.com/flosch/pongo2/v6"
"github.com/gin-gonic/gin"
"github.com/godruoyi/go-snowflake"
"time"
)
func (s *Server) GETIndex(cx *gin.Context) {
ctx := make(pongo2.Context)
ctx["messages"] = storage.Messages
cx.HTML(200, "index", ctx)
}
func (s *Server) POSTIndex(cx *gin.Context) {
m := new(model.Message)
m.Name = cx.PostForm("name")
m.Text = cx.PostForm("text")
m.Time = time.Now()
m.ID = snowflake.ID()
storage.AddMessage(m)
ctx := make(pongo2.Context)
ctx["message"] = m
cx.HTML(200, "message/fragment", ctx)
}

9
server/server.go Normal file
View File

@ -0,0 +1,9 @@
package server
type Server struct {
}
func NewServer() *Server {
s := new(Server)
return s
}