diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c692470 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.vinchent.xyz/vinchent/go-web + +go 1.22.5 diff --git a/main.go b/main.go new file mode 100644 index 0000000..66cf6ab --- /dev/null +++ b/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "html" + "log" + "net/http" +) + +type FooHandler struct{} + +func (foo FooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) +} + +func main() { + var fooHandler FooHandler + http.Handle("/foo", fooHandler) + + http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) + }) + + log.Fatal(http.ListenAndServe(":8080", nil)) +}