MCPcopy Create free account
hub / github.com/1Panel-dev/KubePi / setResultHandler

Method setResultHandler

internal/server/server.go:176–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

174const ContentTypeDownload = "application/download"
175
176func (e *KubePiServer) setResultHandler() {
177 e.rootRoute.Use(func(ctx *context.Context) {
178 ctx.Next()
179 contentType := ctx.ResponseWriter().Header().Get("Content-Type")
180 if contentType == ContentTypeDownload {
181 return
182 }
183 isProxyPath := func() bool {
184 p := ctx.GetCurrentRoute().Path()
185 ss := strings.Split(p, "/")
186 if len(ss) > 0 {
187 if ss[0] == "webkubectl" {
188 return true
189 }
190 }
191 if len(ss) >= 3 {
192 for i := range ss {
193 if ss[i] == "proxy" || ss[i] == "ws" {
194 return true
195 }
196 }
197 }
198 return false
199 }()
200 if !isProxyPath {
201 if ctx.GetStatusCode() >= iris.StatusOK && ctx.GetStatusCode() < iris.StatusBadRequest {
202 if ctx.Values().Get("token") != nil {
203 _, _ = ctx.Write(ctx.Values().Get("token").([]uint8))
204 } else {
205 resp := iris.Map{
206 "success": true,
207 "data": ctx.Values().Get("data"),
208 }
209 _ = ctx.JSON(resp)
210 }
211 }
212 }
213 })
214}
215
216func (e *KubePiServer) setUpErrHandler() {
217 e.rootRoute.OnAnyErrorCode(func(ctx iris.Context) {

Callers 1

bootstrapMethod · 0.95

Calls 3

NextMethod · 0.80
GetMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected