(timeout uint)
| 476 | } |
| 477 | |
| 478 | func (r *Remote) ExecSQLForHosts(timeout uint) ([]string, error) { |
| 479 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) |
| 480 | defer cancel() |
| 481 | |
| 482 | results, err := r.Client.QueryContext(ctx, "select host from mysql.user where user='root';") |
| 483 | if err != nil { |
| 484 | return nil, err |
| 485 | } |
| 486 | if errors.Is(ctx.Err(), context.DeadlineExceeded) { |
| 487 | return nil, buserr.New("ErrExecTimeOut") |
| 488 | } |
| 489 | var rows []string |
| 490 | defer func() { _ = results.Close() }() |
| 491 | for results.Next() { |
| 492 | var host string |
| 493 | if err := results.Scan(&host); err != nil { |
| 494 | continue |
| 495 | } |
| 496 | rows = append(rows, host) |
| 497 | } |
| 498 | return rows, nil |
| 499 | } |
| 500 | |
| 501 | func loadImage(dbType, version string) (string, error) { |
| 502 | cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) |
no test coverage detected