in internal/proxy/proxy.go [484:534]
func NewClient(ctx context.Context, d alloydb.Dialer, l alloydb.Logger, conf *Config) (*Client, error) {
// Check if the caller has configured a dialer.
// Otherwise, initialize a new one.
if d == nil {
dialerOpts, err := conf.DialerOptions(l)
if err != nil {
return nil, fmt.Errorf("error initializing dialer: %v", err)
}
d, err = alloydbconn.NewDialer(ctx, dialerOpts...)
if err != nil {
return nil, fmt.Errorf("error initializing dialer: %v", err)
}
}
c := &Client{
logger: l,
dialer: d,
conf: conf,
}
if conf.FUSEDir != "" {
return configureFUSE(c, conf)
}
var mnts []*socketMount
pc := newPortConfig(conf.Port)
for _, inst := range conf.Instances {
m, err := newSocketMount(ctx, conf, pc, inst)
if err != nil {
for _, m := range mnts {
mErr := m.Close()
if mErr != nil {
l.Errorf("failed to close mount: %v", mErr)
}
}
i, instURIErr := ShortInstURI(inst.Name)
if instURIErr != nil {
// this shouldn't happen because the inst uri is already validated by this point
i = inst.Name
}
return nil, fmt.Errorf("[%v] Unable to mount socket: %v", i, err)
}
l.Infof("[%s] Listening on %s", m.instShort, m.Addr())
mnts = append(mnts, m)
}
c.mnts = mnts
return c, nil
}