Files
blog/tmp_route2.go
T

28 lines
809 B
Go
Raw Normal View History

2026-06-01 17:57:22 +08:00
package main
import (
"log"
"net/http"
"os"
)
var lg *log.Logger
func main() {
lg = log.New(os.Stdout, "[TEST] ", log.LstdFlags)
mux := http.NewServeMux()
mux.HandleFunc("/api/posts/", func(w http.ResponseWriter, r *http.Request) {
lg.Printf("GOT posts/ handler: path=%s method=%s", r.URL.Path, r.Method)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"handler":"posts/","path":"` + r.URL.Path + `"}`))
})
mux.HandleFunc("/api/posts", func(w http.ResponseWriter, r *http.Request) {
lg.Printf("GOT posts handler: path=%s method=%s", r.URL.Path, r.Method)
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"handler":"posts","path":"` + r.URL.Path + `"}`))
})
lg.Println("listening on :8701")
log.Fatal(http.ListenAndServe(":8701", mux))
}