()
| 9 | ) |
| 10 | |
| 11 | func (h *Handler) LoggingHandler() iris.Handler { |
| 12 | return func(ctx *context.Context) { |
| 13 | clusterName := ctx.Params().GetString("name") |
| 14 | |
| 15 | namespace := ctx.URLParam("namespace") |
| 16 | podName := ctx.URLParam("podName") |
| 17 | containerName := ctx.URLParam("containerName") |
| 18 | tailLines := 100 |
| 19 | follow := false |
| 20 | /*是否查看上次失败的容器日志*/ |
| 21 | previous := false |
| 22 | /*是否显示日志时间*/ |
| 23 | timestamps := false |
| 24 | if ctx.URLParamExists("tailLines") { |
| 25 | lines, err := ctx.URLParamInt("tailLines") |
| 26 | if err != nil { |
| 27 | ctx.StatusCode(iris.StatusBadRequest) |
| 28 | return |
| 29 | } |
| 30 | tailLines = lines |
| 31 | } |
| 32 | if ctx.URLParamExists("follow") { |
| 33 | f, err := ctx.URLParamBool("follow") |
| 34 | if err != nil { |
| 35 | ctx.StatusCode(iris.StatusBadRequest) |
| 36 | return |
| 37 | } |
| 38 | follow = f |
| 39 | } |
| 40 | if ctx.URLParamExists("previous") { |
| 41 | p, err := ctx.URLParamBool("previous") |
| 42 | if err != nil { |
| 43 | ctx.StatusCode(iris.StatusBadRequest) |
| 44 | return |
| 45 | } |
| 46 | previous = p |
| 47 | } |
| 48 | if ctx.URLParamExists("timestamps") { |
| 49 | p, err := ctx.URLParamBool("timestamps") |
| 50 | if err != nil { |
| 51 | ctx.StatusCode(iris.StatusBadRequest) |
| 52 | return |
| 53 | } |
| 54 | timestamps = p |
| 55 | } |
| 56 | |
| 57 | sessionId, err := logging.GenLoggingSessionId() |
| 58 | if err != nil { |
| 59 | ctx.StatusCode(iris.StatusInternalServerError) |
| 60 | } |
| 61 | u := ctx.Values().Get("profile") |
| 62 | profile := u.(session.UserProfile) |
| 63 | client, _, _, err := clusteraccess.ClientForUser(clusterName, clusteraccess.User{ |
| 64 | Name: profile.Name, |
| 65 | IsAdministrator: profile.IsAdministrator, |
| 66 | }) |
| 67 | if err != nil { |
| 68 | ctx.StatusCode(iris.StatusInternalServerError) |
no test coverage detected