29 lines
809 B
Go
29 lines
809 B
Go
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))
|
|
}
|