예제 #1
0
파일: middleware.go 프로젝트: dfmonaco/yaag
func Document() gin.HandlerFunc {
	return func(c *gin.Context) {
		if !yaag.IsOn() {
			return
		}
		writer := httptest.NewRecorder()
		apiCall := yaag.APICall{}
		middleware.Before(&apiCall, c.Request)
		c.Next()
		r := c.Request
		if writer.Code != 404 {
			apiCall.MethodType = c.Request.Method
			apiCall.CurrentPath = strings.Split(c.Request.RequestURI, "?")[0]
			apiCall.ResponseBody = ""
			apiCall.ResponseCode = c.Writer.Status()
			headers := map[string]string{}
			for k, v := range c.Writer.Header() {
				log.Println(k, v)
				headers[k] = strings.Join(v, " ")
			}
			apiCall.ResponseHeader = headers
			var baseUrl string
			if r.TLS != nil {
				baseUrl = fmt.Sprintf("https://%s", r.Host)
			} else {
				baseUrl = fmt.Sprintf("http://%s", r.Host)
			}
			yaag.ApiCallValueInstance.BaseLink = baseUrl
			go yaag.GenerateHtml(&apiCall)
		}
	}
}
예제 #2
0
func (y *YaagHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if !yaag.IsOn() {
		y.next(w, r)
		return
	}
	writer := httptest.NewRecorder()
	apiCall := yaag.APICall{}
	Before(&apiCall, r)
	y.next(writer, r)
	After(&apiCall, writer, w, r)
}
예제 #3
0
파일: middleware.go 프로젝트: kiyor/yaag
func Document(c martini.Context, w http.ResponseWriter, r *http.Request) {
	if !yaag.IsOn() {
		c.Next()
		return
	}
	apiCall := models.ApiCall{}
	writer := httptest.NewRecorder()
	c.MapTo(writer, (*http.ResponseWriter)(nil))
	middleware.Before(&apiCall, r)
	c.Next()
	middleware.After(&apiCall, writer, w, r)
}
예제 #4
0
func HandleFunc(next func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		if !yaag.IsOn() {
			next(w, r)
			return
		}
		apiCall := yaag.APICall{}
		writer := httptest.NewRecorder()
		Before(&apiCall, r)
		next(writer, r)
		After(&apiCall, writer, w, r)
	}
}
예제 #5
0
파일: middleware.go 프로젝트: kiyor/yaag
func Document() gin.HandlerFunc {
	return func(c *gin.Context) {
		if !yaag.IsOn() {
			return
		}
		writer := httptest.NewRecorder()
		apiCall := models.ApiCall{}
		middleware.Before(&apiCall, c.Request)
		c.Next()
		if writer.Code != 404 {
			apiCall.MethodType = c.Request.Method
			apiCall.CurrentPath = strings.Split(c.Request.RequestURI, "?")[0]
			apiCall.ResponseBody = ""
			apiCall.ResponseCode = c.Writer.Status()
			headers := map[string]string{}
			for k, v := range c.Writer.Header() {
				log.Println(k, v)
				headers[k] = strings.Join(v, " ")
			}
			apiCall.ResponseHeader = headers
			go yaag.GenerateHtml(&apiCall)
		}
	}
}