initial
This commit is contained in:
29
server/index.go
Normal file
29
server/index.go
Normal 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
9
server/server.go
Normal file
@ -0,0 +1,9 @@
|
||||
package server
|
||||
|
||||
type Server struct {
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
s := new(Server)
|
||||
return s
|
||||
}
|
Reference in New Issue
Block a user