You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
309 B

  1. package common
  2. import (
  3. "net"
  4. "strings"
  5. )
  6. // protoAddr: e.g. "tcp://127.0.0.1:8080" or "unix:///tmp/test.sock"
  7. func Connect(protoAddr string) (net.Conn, error) {
  8. parts := strings.SplitN(protoAddr, "://", 2)
  9. proto, address := parts[0], parts[1]
  10. conn, err := net.Dial(proto, address)
  11. return conn, err
  12. }