36 lines
668 B
Go
36 lines
668 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"github.com/a-h/templ"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func getRoot(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Printf("Got / request\n")
|
|
io.WriteString(w, "Website root page\n")
|
|
}
|
|
|
|
func getHello(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Printf("Got /hello request\n")
|
|
io.WriteString(w, "hello HTTP\n")
|
|
}
|
|
|
|
func main() {
|
|
|
|
component := root()
|
|
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/", templ.Handler(component))
|
|
|
|
err := http.ListenAndServe(":3000", mux)
|
|
if errors.Is(err, http.ErrServerClosed) {
|
|
fmt.Printf("server closed\n")
|
|
} else if err != nil {
|
|
fmt.Printf("error starting server: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|