github.com/456vv/valexa@v1.0.2-0.20200706152242-1fb922d71ce5/EchoIntent.go (about) 1 package valexa 2 3 import ( 4 "net/http" 5 "context" 6 "io" 7 ) 8 9 //Echo意图处理 10 type EchoIntent struct{ 11 Request *EchoRequest //Echo请求 12 Response *EchoResponse //Echo响应 13 App *EchoApplication //Echo配置 14 } 15 16 //服务处理 17 // w http.ResponseWriter http响应对象 18 // r *http.Request http请求对象 19 func (T *EchoIntent) ServeHTTP(w http.ResponseWriter, r *http.Request){ 20 if T.App.HandleFunc != nil { 21 r = r.WithContext(context.WithValue(r.Context(), r.URL.Path, T)) 22 T.App.HandleFunc(w, r) 23 return 24 } 25 26 w.Header().Set("Content-Type", "application/json;charset=UTF-8") 27 io.WriteString(w, T.Response.String()) 28 }