2024-01-22 21:25:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-22 23:07:14 +00:00
|
|
|
"fmt"
|
2024-01-22 21:25:34 +00:00
|
|
|
"net/http"
|
2024-01-22 23:07:14 +00:00
|
|
|
"strconv"
|
2024-01-22 21:25:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// home ...
|
|
|
|
func home(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path != "/" {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Write([]byte("Hello from snippetbox.chaosfem.tw"))
|
|
|
|
}
|
|
|
|
|
|
|
|
// snippetView ...
|
|
|
|
func snippetView(w http.ResponseWriter, r *http.Request) {
|
2024-01-22 23:07:14 +00:00
|
|
|
id, err := strconv.Atoi(r.URL.Query().Get("id"))
|
|
|
|
if err != nil || id < 1 {
|
|
|
|
http.NotFound(w, r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "It's snippet id: %d", id)
|
2024-01-22 21:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// snippetCreate ...
|
|
|
|
func snippetCreate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Allow", "POST")
|
|
|
|
|
|
|
|
if r.Method != http.MethodPost {
|
|
|
|
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Write([]byte("Creating a snippet!"))
|
|
|
|
}
|