diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..82c6cf7 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ + +run: + templ generate && go run cmd/main.go diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..adfdac7 --- /dev/null +++ b/cmd/main.go @@ -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) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..36517b6 --- /dev/null +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cb2a401 --- /dev/null +++ b/go.sum @@ -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= diff --git a/templates/hello.templ b/templates/hello.templ new file mode 100644 index 0000000..6424008 --- /dev/null +++ b/templates/hello.templ @@ -0,0 +1,5 @@ +package templates + +templ Hello(name string) { +
Hello, { name }
+} diff --git a/templates/hello_templ.go b/templates/hello_templ.go new file mode 100644 index 0000000..dc416fd --- /dev/null +++ b/templates/hello_templ.go @@ -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("
") + 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("
") + if err != nil { + return err + } + if !templIsBuffer { + _, err = io.Copy(w, templBuffer) + } + return err + }) +} diff --git a/templates/status.templ b/templates/status.templ new file mode 100644 index 0000000..17996ca --- /dev/null +++ b/templates/status.templ @@ -0,0 +1,25 @@ +package templates + +templ GetStatus(statusOne string, statusTwo string) { + +
+
+ + + + + +
+
+} diff --git a/templates/status_templ.go b/templates/status_templ.go new file mode 100644 index 0000000..1ee86eb --- /dev/null +++ b/templates/status_templ.go @@ -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("
") + if err != nil { + return err + } + if !templIsBuffer { + _, err = io.Copy(w, templBuffer) + } + return err + }) +}