diff --git a/apiv1.go b/apiv1.go new file mode 100644 index 0000000..ce942c4 --- /dev/null +++ b/apiv1.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" + "net/http" + "net/http/httputil" +) + +const apiV1Prefix = "/api/v1/" + +//apiV1Main version 1 main entry for all wechat callbacks +// +func apiV1Main(w http.ResponseWriter, r *http.Request) { + logRequestDebug(httputil.DumpRequest(r, true)) + + path := r.URL.Path[len(apiV1Prefix):] + fmt.Fprintf(w, "Protocol = %s, path= %s \n", r.Method, path) +} diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..d9663fe --- /dev/null +++ b/debug.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + log "github.com/sirupsen/logrus" +) + +func logRequestDebug(data []byte, err error) { + if err == nil { + fmt.Printf("%s\n\n", string(data)) + } else { + log.Fatalf("%s\n\n", err) + } +} diff --git a/main.go b/main.go index 13b61dc..2f31032 100644 --- a/main.go +++ b/main.go @@ -32,26 +32,15 @@ func setupRootFileServer() { } func setupHTTPHandler() { - http.HandleFunc("/api", HelloHandler) - //http.HandleFunc("/upload", HelloHandler) - //http.HandleFunc("/crmfiles/", HelloHandler) - //http.HandleFunc("/dumprequest", HelloHandler) - //http.HandleFunc("/MP_verify_6JqVkftKr39GMakA.txt", HelloHandler) - //http.HandleFunc("/spa/redirect", HelloHandler) - //http.HandleFunc("/iapi/getAccessToken", HelloHandler) - //http.HandleFunc("/iapi/createWechatQr", HelloHandler) - //http.HandleFunc("/crmpixel.png", HelloHandler) //tracking pixel. - //http.HandleFunc("/crmcache", HelloHandler) - //http.HandleFunc("/spa/editprofile", HelloHandler) - //http.HandleFunc("/spa/livecast", HelloHandler) - //http.HandleFunc("/spa/editmeeting", HelloHandler) + http.HandleFunc(apiV1Prefix, apiV1Main) + http.HandleFunc("/dummy/", dummyHandler) log.Printf("Server started at %s:%s\n", config.Host, config.Port) log.Fatal(http.ListenAndServe(config.Host+":"+config.Port, nil)) } -func HelloHandler(w http.ResponseWriter, r *http.Request) { +func dummyHandler(w http.ResponseWriter, r *http.Request) { p := loan.People{} p.FakeNew() fmt.Fprintf(w, "Hello, there %s, %+v\n", loan.Version, p)