learn-go/snippetbox/cmd/web/main.go

29 lines
608 B
Go
Raw Normal View History

package main
import (
2024-01-23 22:08:59 +00:00
"flag"
"log"
"net/http"
)
// main it's the snippetbox webapp
func main() {
2024-01-23 22:08:59 +00:00
//configuration
addr := flag.String("addr", ":4000", "HTTP network address")
flag.Parse()
mux := http.NewServeMux()
2024-01-23 22:08:59 +00:00
// 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)
2024-01-23 22:08:59 +00:00
log.Printf("starting a server on %s", *addr)
err := http.ListenAndServe(*addr, mux)
log.Fatal(err)
}