Exemplo n.º 1
0
func (y *YaagHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if !yaag.IsOn() {
		y.nextHandler.ServeHTTP(w, r)
		return
	}
	writer := httptest.NewRecorder()
	apiCall := models.ApiCall{}
	Before(&apiCall, r)
	y.nextHandler.ServeHTTP(writer, r)
	After(&apiCall, writer, w, r)
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
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 := models.ApiCall{}
		writer := httptest.NewRecorder()
		Before(&apiCall, r)
		next(writer, r)
		After(&apiCall, writer, w, r)
	}
}
Exemplo n.º 4
0
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)
		}
	}
}
Exemplo n.º 5
0
func Add(w http.ResponseWriter, key, value string) {
	if yaag.IsOn() {
		w.Header().Add("Yaag-Annotation-"+key, value)
	}
}