learn-go/snippetbox/cmd/web/main.go
tamsin johnson cf5c574b57 lets-go:3.1
2024-01-23 14:08:59 -08:00

29 lines
608 B
Go

package main
import (
"flag"
"log"
"net/http"
)
// main it's the snippetbox webapp
func main() {
//configuration
addr := flag.String("addr", ":4000", "HTTP network address")
flag.Parse()
mux := http.NewServeMux()
// setup server for static files
fileServer := http.FileServer(http.Dir("./ui/static"))
mux.Handle("/static/", http.StripPrefix("/static", fileServer))
mux.HandleFunc("/", home)
mux.HandleFunc("/snippet/view", snippetView)
mux.HandleFunc("/snippet/create", snippetCreate)
log.Printf("starting a server on %s", *addr)
err := http.ListenAndServe(*addr, mux)
log.Fatal(err)
}