diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adb36c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe \ No newline at end of file diff --git a/main.go b/main.go index 70a7fe5..baf2cd9 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,33 @@ package main -import "fmt" +import ( + "log" + "net/http" +) + +func home(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } + w.Write([]byte("Hello from Snippetbox")) +} + +func snippetView(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("Display a specific snippet...")) +} + +func snippetCreate(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("Create a new snippet")) +} func main() { - fmt.Println("Hello world!") + mux := http.NewServeMux() + mux.HandleFunc("/", home) + mux.HandleFunc("/snippet/view", snippetView) + mux.HandleFunc("/snippet/create", snippetCreate) + + log.Print("Starting server on :4000") + err := http.ListenAndServe(":4000", mux) + log.Fatal(err) }