package local_socket import ( "net" "os" "path/filepath" ) // LocalSocket is a socket to communicate with other processes in the same box. // LocalSocket satisfies io.Reader, io.Writer, net.Conn interfaces. type LocalSocket struct { conn *net.UnixConn } // NewLocalSocket creates LocalSocket instance func NewLocalSocket(pathName string) (*LocalSocket, error) { socketType := "unix" // SOCK_STREAM conn, err := net.DialUnix(socketType, nil, &net.UnixAddr{filepath.Join(os.TempDir(), pathName), socketType}) if err != nil { return nil, err } return newLocalSocket(conn), nil } func newLocalSocket(conn *net.UnixConn) *LocalSocket { return &LocalSocket{ conn: conn, } }