ch2.3
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.exe
|
||||
30
main.go
30
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user