limitLines 限制输出行数
(output string, maxLines int)
| 290 | |
| 291 | // limitLines 限制输出行数 |
| 292 | func (t *BashOutputTool) limitLines(output string, maxLines int) string { |
| 293 | if maxLines <= 0 || output == "" { |
| 294 | return output |
| 295 | } |
| 296 | |
| 297 | lines := strings.Split(output, "\n") |
| 298 | if len(lines) <= maxLines { |
| 299 | return output |
| 300 | } |
| 301 | |
| 302 | // 返回最后的maxLines行 |
| 303 | return strings.Join(lines[len(lines)-maxLines:], "\n") |
| 304 | } |
| 305 | |
| 306 | // filterByTime 按时间过滤输出 |
| 307 | func (t *BashOutputTool) filterByTime(output, since string) string { |