Serve starts proxying connections for all configured instances using the associated socket.
(ctx context.Context, notify func())
| 669 | // Serve starts proxying connections for all configured instances using the |
| 670 | // associated socket. |
| 671 | func (c *Client) Serve(ctx context.Context, notify func()) error { |
| 672 | ctx, cancel := context.WithCancel(ctx) |
| 673 | defer cancel() |
| 674 | |
| 675 | if c.fuseDir != "" { |
| 676 | return c.serveFuse(ctx, notify) |
| 677 | } |
| 678 | |
| 679 | if c.conf.RunConnectionTest { |
| 680 | c.logger.Infof("Connection test started") |
| 681 | if _, err := c.CheckConnections(ctx); err != nil { |
| 682 | c.logger.Errorf("Connection test failed") |
| 683 | return err |
| 684 | } |
| 685 | c.logger.Infof("Connection test passed") |
| 686 | } |
| 687 | |
| 688 | exitCh := make(chan error) |
| 689 | for _, m := range c.mnts { |
| 690 | go func(mnt *socketMount) { |
| 691 | err := c.serveSocketMount(ctx, mnt) |
| 692 | if err != nil { |
| 693 | select { |
| 694 | // Best effort attempt to send error. |
| 695 | // If this send fails, it means the reading goroutine has |
| 696 | // already pulled a value out of the channel and is no longer |
| 697 | // reading any more values. In other words, we report only the |
| 698 | // first error. |
| 699 | case exitCh <- err: |
| 700 | default: |
| 701 | return |
| 702 | } |
| 703 | } |
| 704 | }(m) |
| 705 | } |
| 706 | notify() |
| 707 | return <-exitCh |
| 708 | } |
| 709 | |
| 710 | // MultiErr is a group of errors wrapped into one. |
| 711 | type MultiErr []error |