MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Response

Method Response

controllers/api/BaseController.go:178–200  ·  view source on GitHub ↗

###################################//

(httpStatus int, message string, data ...interface{})

Source from the content-addressed store, hash-verified

176//###################################//
177
178func (this *BaseController) Response(httpStatus int, message string, data ...interface{}) {
179 resp := APIResponse{Message: message}
180 if len(data) > 0 {
181 resp.Data = data[0]
182 }
183 returnJSON, err := json.Marshal(resp)
184 if err != nil {
185 beego.Error(err)
186 }
187
188 this.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json; charset=utf-8")
189 if strings.Contains(strings.ToLower(this.Ctx.Request.Header.Get("Accept-Encoding")), "gzip") { //gzip压缩
190 this.Ctx.ResponseWriter.Header().Set("Content-Encoding", "gzip")
191 this.Ctx.ResponseWriter.WriteHeader(httpStatus)
192 w := gzip.NewWriter(this.Ctx.ResponseWriter)
193 defer w.Close()
194 w.Write(returnJSON)
195 w.Flush()
196 } else {
197 io.WriteString(this.Ctx.ResponseWriter, string(returnJSON))
198 }
199 this.StopRun()
200}
201
202// 验证access token
203func (this *BaseController) Prepare() {

Callers 15

PrepareMethod · 0.95
PrepareMethod · 0.80
LogoutMethod · 0.80
GetBookmarksMethod · 0.80
StarMethod · 0.80
SetBookmarksMethod · 0.80
DeleteBookmarksMethod · 0.80
ChangeAvatarMethod · 0.80
PostCommentMethod · 0.80
ChangePasswordMethod · 0.80
SignTodayMethod · 0.80
SignStatusMethod · 0.80

Calls 2

stringFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected