func()

in internal/output/gcppubsub/gcppubsub.go [47:81]


func (o *Output) DialContext(ctx context.Context) error {
	// Disable HTTP keep-alives to ensure no extra goroutines hang around.
	httpClient := http.Client{Transport: &http.Transport{DisableKeepAlives: true}}

	// Sanity check the emulator.
	resp, err := httpClient.Get("http://" + o.opts.Addr)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	_, err = io.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("unexpected status code: %v", resp.StatusCode)
	}

	if o.opts.GCPPubsubOptions.Clear {
		if err := o.clear(); err != nil {
			return err
		}
	}

	if err := o.createTopic(); err != nil {
		return err
	}

	if err := o.createSubscription(); err != nil {
		return err
	}

	return nil
}