adding in core
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/talksik/online-status-htmx-golang/templates"
|
||||
)
|
||||
|
||||
var (
|
||||
statusOne string
|
||||
statusTwo string
|
||||
)
|
||||
|
||||
func getStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
component := templates.GetStatus(statusOne, statusTwo)
|
||||
component.Render(r.Context(), w)
|
||||
}
|
||||
|
||||
func updateStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO: read request and update statuses
|
||||
|
||||
println("changing status")
|
||||
|
||||
getStatusHandler(w, r)
|
||||
}
|
||||
|
||||
func main() {
|
||||
println("yo")
|
||||
|
||||
component := templates.Hello("John")
|
||||
http.Handle("/hello", templ.Handler(component))
|
||||
|
||||
http.HandleFunc("/", getStatusHandler)
|
||||
http.HandleFunc("/changestatus", updateStatusHandler)
|
||||
|
||||
fmt.Println("Listening on :3000")
|
||||
http.ListenAndServe(":3000", nil)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
module github.com/talksik/online-status-htmx-golang
|
||||
|
||||
go 1.21.0
|
||||
|
||||
require github.com/a-h/templ v0.2.316 // indirect
|
||||
@@ -0,0 +1,2 @@
|
||||
github.com/a-h/templ v0.2.316 h1:s52MtlmUG9vg2xDSWTR/cnc5VbukVjCJyNvprCNFp0Q=
|
||||
github.com/a-h/templ v0.2.316/go.mod h1:3oc37WS5rpDvFGi6yeknvTKt50xCu67ywQsM43Wr4PU=
|
||||
@@ -0,0 +1,5 @@
|
||||
package templates
|
||||
|
||||
templ Hello(name string) {
|
||||
<div>Hello, { name }</div>
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Code generated by templ@v0.2.316 DO NOT EDIT.
|
||||
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
func Hello(name string) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
|
||||
templBuffer, templIsBuffer := w.(*bytes.Buffer)
|
||||
if !templIsBuffer {
|
||||
templBuffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templBuffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
var_1 := templ.GetChildren(ctx)
|
||||
if var_1 == nil {
|
||||
var_1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, err = templBuffer.WriteString("<div>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var_2 := `Hello, `
|
||||
_, err = templBuffer.WriteString(var_2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var var_3 string = name
|
||||
_, err = templBuffer.WriteString(templ.EscapeString(var_3))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</div>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !templIsBuffer {
|
||||
_, err = io.Copy(w, templBuffer)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package templates
|
||||
|
||||
templ GetStatus(statusOne string, statusTwo string) {
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<div id="main" class="flex flex-row gap-2">
|
||||
<form
|
||||
hx-post="/changestatus"
|
||||
hx-target="#main"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<input
|
||||
id="statusH" name="Status H" type="text"
|
||||
placeholder="Enter status H"
|
||||
value={ statusOne }
|
||||
/>
|
||||
|
||||
<input
|
||||
id="statusA" name="Status A" type="text"
|
||||
placeholder="Enter status, A" value={ statusTwo }
|
||||
/>
|
||||
|
||||
<button type="submit" class="button is-primary">Update</button>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// Code generated by templ@v0.2.316 DO NOT EDIT.
|
||||
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
|
||||
func GetStatus(statusOne string, statusTwo string) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
|
||||
templBuffer, templIsBuffer := w.(*bytes.Buffer)
|
||||
if !templIsBuffer {
|
||||
templBuffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templBuffer)
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
var_1 := templ.GetChildren(ctx)
|
||||
if var_1 == nil {
|
||||
var_1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, err = templBuffer.WriteString("<script src=\"https://cdn.tailwindcss.com\">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var_2 := ``
|
||||
_, err = templBuffer.WriteString(var_2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</script><div id=\"main\" class=\"flex flex-row gap-2\"><form hx-post=\"/changestatus\" hx-target=\"#main\" hx-swap=\"outerHTML\"><input id=\"statusH\" name=\"Status H\" type=\"text\" placeholder=\"Enter status H\" value=\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(templ.EscapeString(statusOne))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("\"><input id=\"statusA\" name=\"Status A\" type=\"text\" placeholder=\"Enter status, A\" value=\"")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString(templ.EscapeString(statusTwo))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("\"><button type=\"submit\" class=\"button is-primary\">")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var_3 := `Update`
|
||||
_, err = templBuffer.WriteString(var_3)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = templBuffer.WriteString("</button></form></div>")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !templIsBuffer {
|
||||
_, err = io.Copy(w, templBuffer)
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user