type CredsRequirement … const CREDS_REQUIRE … const CREDS_DROP … const CREDS_OPTIONAL … func extractHostFromHostPort(ep string) string { … } // mustSplit2 returns the values from strings.SplitN(s, sep, 2). // If sep is not found, it returns ("", "", false) instead. func mustSplit2(s, sep string) (string, string) { … } func schemeToCredsRequirement(schema string) CredsRequirement { … } // This function translates endpoints names supported by etcd server into // endpoints as supported by grpc with additional information // (server_name for cert validation, requireCreds - whether certs are needed). // The main differences: // - etcd supports unixs & https names as opposed to unix & http to // distinguish need to configure certificates. // - etcd support http(s) names as opposed to tcp supported by grpc/dial method. // - etcd supports unix(s)://local-file naming schema // (as opposed to unix:local-file canonical name used by grpc for current dir files). // - Within the unix(s) schemas, the last segment (filename) without 'port' (content after colon) // is considered serverName - to allow local testing of cert-protected communication. // // See more: // - https://github.com/grpc/grpc-go/blob/26c143bd5f59344a4b8a1e491e0f5e18aa97abc7/internal/grpcutil/target.go#L47 // - https://golang.org/pkg/net/#Dial // - https://github.com/grpc/grpc/blob/master/doc/naming.md func translateEndpoint(ep string) (addr string, serverName string, requireCreds CredsRequirement) { … } // RequiresCredentials returns whether given endpoint requires // credentials/certificates for connection. func RequiresCredentials(ep string) CredsRequirement { … } // Interpret endpoint parses an endpoint of the form // (http|https)://<host>*|(unix|unixs)://<path>) // and returns low-level address (supported by 'net') to connect to, // and a server name used for x509 certificate matching. func Interpret(ep string) (address string, serverName string) { … }