ch2.5
This commit is contained in:
9
main.go
9
main.go
@@ -1,8 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func home(w http.ResponseWriter, r *http.Request) {
|
func home(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -14,7 +16,12 @@ func home(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func snippetView(w http.ResponseWriter, r *http.Request) {
|
func snippetView(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte("Display a specific snippet..."))
|
id, err := strconv.Atoi(r.URL.Query().Get("id"))
|
||||||
|
if err != nil || id < 1 {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "Display a specific snippet with ID %d...", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func snippetCreate(w http.ResponseWriter, r *http.Request) {
|
func snippetCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user