From a3f90562d55b77c2a00a4ec8b72bc5423a3631cf Mon Sep 17 00:00:00 2001 From: talksik Date: Sun, 9 Nov 2025 11:54:47 -0800 Subject: [PATCH] basic web server with standard library --- cmd/main.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +++ 2 files changed, 55 insertions(+) create mode 100644 cmd/main.go create mode 100644 go.mod diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..b0a8170 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + "html/template" + "log" + "net/http" + "os" +) + +var x = 2 + +func testTemplate() { + const tpl = ` + + + + + {{.Title}} + + + {{range .Items}}
{{ . }}
{{else}}
no rows
{{end}} + +` + + t, err := template.New("default").Parse(tpl) + if err != nil { + log.Fatalf("%v", err) + } + + data := struct { + Title string + Items []string + }{ + Title: "Hello", + Items: []string{"yo", template.HTMLEscapeString("what's up")}, + } + err = t.Execute(os.Stdout, data) + if err != nil { + log.Fatalf("%v", err) + } + +} + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + w.WriteHeader(200) + fmt.Fprintf(w, "Welcome to the home page!") + }) + log.Printf("listening on port 8080") + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..544e689 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/flowy-live/go-htmx + +go 1.24.0