| 337 | } |
| 338 | |
| 339 | func tryOpen(ctx context.Context, url string, log logpkg.Logger) error { |
| 340 | timeoutCtx, cancel := context.WithTimeout(ctx, time.Second) |
| 341 | defer cancel() |
| 342 | |
| 343 | req, err := http.NewRequestWithContext(timeoutCtx, "GET", url, nil) |
| 344 | if err != nil { |
| 345 | return err |
| 346 | } |
| 347 | |
| 348 | client := &http.Client{Transport: &http.Transport{ |
| 349 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 350 | }} |
| 351 | |
| 352 | resp, err := client.Do(req) |
| 353 | if err != nil { |
| 354 | return err |
| 355 | } |
| 356 | defer func() { |
| 357 | if resp != nil { |
| 358 | resp.Body.Close() |
| 359 | } |
| 360 | }() |
| 361 | |
| 362 | if resp != nil && resp.StatusCode != http.StatusBadGateway && resp.StatusCode != http.StatusServiceUnavailable { |
| 363 | select { |
| 364 | case <-ctx.Done(): |
| 365 | return nil |
| 366 | case <-time.After(time.Second): |
| 367 | } |
| 368 | _ = open.Start(url) |
| 369 | log.Donef("Successfully opened %s", url) |
| 370 | return nil |
| 371 | } |
| 372 | |
| 373 | return fmt.Errorf("not reachable") |
| 374 | } |
| 375 | |
| 376 | func (d *devPod) startLogs(ctx devspacecontext.Context, devPodConfig *latest.DevPod, selectedPod *selector.SelectedPodContainer, parent *tomb.Tomb) error { |
| 377 | ctx = ctx.WithLogger(ctx.Log().WithPrefixColor("logs ", "yellow+b")) |