Compare commits
No commits in common. "9ded6a46151fb0c36296e77dc8f5dcdab65c2802" and "9c5b17261fa320e5e69f06d33081adf8bc21cdef" have entirely different histories.
9ded6a4615
...
9c5b17261f
14
go.mod
14
go.mod
@ -1,17 +1,3 @@
|
|||||||
module gitea.elara.ws/Hazel/hangman
|
module gitea.elara.ws/Hazel/hangman
|
||||||
|
|
||||||
go 1.24.2
|
go 1.24.2
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0 // indirect
|
|
||||||
github.com/labstack/echo/v4 v4.13.4 // indirect
|
|
||||||
github.com/labstack/gommon v0.4.2 // indirect
|
|
||||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
|
||||||
golang.org/x/crypto v0.38.0 // indirect
|
|
||||||
golang.org/x/net v0.40.0 // indirect
|
|
||||||
golang.org/x/sys v0.33.0 // indirect
|
|
||||||
golang.org/x/text v0.25.0 // indirect
|
|
||||||
)
|
|
||||||
|
23
go.sum
23
go.sum
@ -1,23 +0,0 @@
|
|||||||
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0 h1:aYo8nnk3ojoQkP5iErif5Xxv0Mo0Ga/FR5+ffl/7+Nk=
|
|
||||||
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0/go.mod h1:8AuBTZBRSFqEYBPYULd+NN474/zZBLP+6WeT5S9xlAc=
|
|
||||||
github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
|
|
||||||
github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
|
|
||||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
|
||||||
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
|
||||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
|
||||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
|
||||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
|
||||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
|
||||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
|
||||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
|
||||||
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
|
|
||||||
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
|
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
|
||||||
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
|
||||||
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
|
|
||||||
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
|
|
@ -1,13 +0,0 @@
|
|||||||
package rest_handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/hangman/internal/session"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateSession(c echo.Context) error {
|
|
||||||
s := session.NewSession()
|
|
||||||
return c.JSON(http.StatusOK, s)
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package session
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
petname "github.com/dustinkirkland/golang-petname"
|
|
||||||
)
|
|
||||||
|
|
||||||
type User struct {
|
|
||||||
Name string
|
|
||||||
PublicKey string
|
|
||||||
PrivateKey string
|
|
||||||
}
|
|
||||||
|
|
||||||
var lastSessionId int = 0
|
|
||||||
var sessionStorage []Session = []Session{}
|
|
||||||
var nameToSession map[string]*Session = make(map[string]*Session)
|
|
||||||
|
|
||||||
type Session struct {
|
|
||||||
id int
|
|
||||||
Name string
|
|
||||||
Users []User
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSession() Session {
|
|
||||||
sessionName := petname.Generate(3, "-")
|
|
||||||
|
|
||||||
s := Session{
|
|
||||||
id: lastSessionId,
|
|
||||||
Name: sessionName,
|
|
||||||
Users: []User{},
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionStorage = append(sessionStorage, s)
|
|
||||||
nameToSession[sessionName] = &s
|
|
||||||
lastSessionId++
|
|
||||||
|
|
||||||
fmt.Println(sessionName)
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSession(name string) *Session {
|
|
||||||
return nameToSession[name]
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package view_handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateSession(c echo.Context) error {
|
|
||||||
return c.Render(http.StatusOK, "create_session", map[string]interface{}{
|
|
||||||
"name": "create session",
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package view_handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateUser(c echo.Context) error {
|
|
||||||
return c.Render(http.StatusOK, "create_user", map[string]interface{}{
|
|
||||||
"name": c.Param("name"),
|
|
||||||
})
|
|
||||||
}
|
|
43
main.go
43
main.go
@ -1,46 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"gitea.elara.ws/Hazel/hangman/internal/rest_handler"
|
|
||||||
"gitea.elara.ws/Hazel/hangman/internal/view_handler"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TemplateRegistry struct {
|
|
||||||
templates map[string]*template.Template
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement e.Renderer interface
|
|
||||||
func (t *TemplateRegistry) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
|
||||||
tmpl, ok := t.templates[name]
|
|
||||||
if !ok {
|
|
||||||
err := errors.New("Template not found -> " + name)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return tmpl.ExecuteTemplate(w, "base.html", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("wanna play hangman? Well ya cant since it isn't implemented yet..")
|
fmt.Println("wanna play hangman? Well ya cant since it isn't implemented yet.")
|
||||||
|
|
||||||
e := echo.New()
|
|
||||||
|
|
||||||
templates := make(map[string]*template.Template)
|
|
||||||
templates["create_session"] = template.Must(template.ParseFiles("templates/create_session.html", "templates/base.html"))
|
|
||||||
templates["create_user"] = template.Must(template.ParseFiles("templates/create_user.html", "templates/base.html"))
|
|
||||||
e.Renderer = &TemplateRegistry{
|
|
||||||
templates: templates,
|
|
||||||
}
|
|
||||||
|
|
||||||
e.GET("/", view_handler.CreateSession)
|
|
||||||
e.GET("/api/session", rest_handler.CreateSession)
|
|
||||||
|
|
||||||
e.GET("/:name", view_handler.CreateUser)
|
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start(":1323"))
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html data-theme="dark">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>{{template "title" .}}</title>
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/bulma.min.css">
|
|
||||||
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/anchor@3.x.x/dist/cdn.min.js"></script>
|
|
||||||
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container mt-5">
|
|
||||||
{{template "body" .}}
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,25 +0,0 @@
|
|||||||
{{define "title"}}
|
|
||||||
create or join session | {{index . "name"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "body"}}
|
|
||||||
<button class="button is-primary" id="createSessionBtn">create session</button>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.getElementById('createSessionBtn').addEventListener('click', async function() {
|
|
||||||
const response = await fetch('/api/session', {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
window.open(`/${data.Name}`);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{{end}}
|
|
@ -1,7 +0,0 @@
|
|||||||
{{define "title"}}
|
|
||||||
create user | {{index . "name"}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "body"}}
|
|
||||||
<h1>Current Session: {{index . "name"}}</h1>
|
|
||||||
{{end}}
|
|
Loading…
x
Reference in New Issue
Block a user