(ctx context.Context, conf *Config, pc *portConfig, inst InstanceConnConfig)
| 846 | } |
| 847 | |
| 848 | func (c *Client) newSocketMount(ctx context.Context, conf *Config, pc *portConfig, inst InstanceConnConfig) (*socketMount, error) { |
| 849 | var ( |
| 850 | // network is one of "tcp" or "unix" |
| 851 | network string |
| 852 | // address is either a TCP host port, or a Unix socket |
| 853 | address string |
| 854 | err error |
| 855 | ) |
| 856 | // IF |
| 857 | // a global Unix socket directory is NOT set AND |
| 858 | // an instance-level Unix socket is NOT set |
| 859 | // (e.g., I didn't set a Unix socket globally or for this instance) |
| 860 | // OR |
| 861 | // an instance-level TCP address or port IS set |
| 862 | // (e.g., I'm overriding any global settings to use TCP for this |
| 863 | // instance) |
| 864 | // use a TCP listener. |
| 865 | // Otherwise, use a Unix socket. |
| 866 | if networkType(conf, inst) == "tcp" { |
| 867 | network = "tcp" |
| 868 | |
| 869 | a := conf.Addr |
| 870 | if inst.Addr != "" { |
| 871 | a = inst.Addr |
| 872 | } |
| 873 | if ip := net.ParseIP(a); ip != nil { |
| 874 | if ip.To4() != nil { |
| 875 | network = "tcp4" |
| 876 | } else { |
| 877 | network = "tcp6" |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | var np int |
| 882 | switch { |
| 883 | case inst.Port != 0: |
| 884 | np = inst.Port |
| 885 | case conf.Port != 0: |
| 886 | np = pc.nextPort() |
| 887 | case conf.SQLDataEnabled || inst.SQLDataEnabled != nil && *inst.SQLDataEnabled: |
| 888 | // TODO: Only Postgres is supported by the SqlDataService |
| 889 | // when more engines are supported, this code will need to change. |
| 890 | np = pc.nextDBPort("POSTGRES") |
| 891 | default: |
| 892 | version, err := c.dialer.EngineVersion(ctx, inst.Name) |
| 893 | // Exit if the port is not specified for inactive instance |
| 894 | if err != nil { |
| 895 | c.logger.Errorf("[%v] could not resolve instance version: %v", inst.Name, err) |
| 896 | return nil, err |
| 897 | } |
| 898 | np = pc.nextDBPort(version) |
| 899 | } |
| 900 | |
| 901 | address = net.JoinHostPort(a, fmt.Sprint(np)) |
| 902 | } else { |
| 903 | network = "unix" |
| 904 | |
| 905 | var version string |
no test coverage detected