-
Notifications
You must be signed in to change notification settings - Fork 6
/
dial.go
53 lines (49 loc) · 1018 Bytes
/
dial.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package seth
import (
"fmt"
"io"
"net"
"os"
"os/user"
"path/filepath"
"runtime"
)
func home() string {
if h := os.Getenv("HOME"); h != "" {
return h
}
if u, err := user.Current(); err == nil {
return u.HomeDir
}
return ""
}
// IPCPath returns a closure that dials a unix socket.
//
// It can be used in NewClient like
//
// NewClient(IPCPath("/path/to/geth.ipc"))
//
func IPCPath(s string) func() (io.ReadWriteCloser, error) {
return func() (io.ReadWriteCloser, error) {
return net.Dial("unix", s)
}
}
// IPCDial dials geth over local IPC
//
// It can be used in NewClient like
//
// NewClient(IPCDial)
//
func IPCDial() (io.ReadWriteCloser, error) {
var sockpath string
switch runtime.GOOS {
case "darwin":
sockpath = filepath.Join(home(), "Library", "Ethereum")
case "linux":
sockpath = filepath.Join(home(), ".ethereum")
default:
return nil, fmt.Errorf("unsupported GOOS %q", runtime.GOOS)
}
sockpath = filepath.Join(sockpath, "geth.ipc")
return net.Dial("unix", sockpath)
}