-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfile_client.go
71 lines (55 loc) · 1.36 KB
/
file_client.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package fanuc
import (
"fmt"
"io/ioutil"
"os"
"path"
)
type FileClient struct {
dir string
base *ParseClient
}
func NewFileClient(dir string) (*FileClient, error) {
info, err := os.Stat(dir)
if err != nil {
return nil, fmt.Errorf("%q does not exist", dir)
}
if !info.IsDir() {
return nil, fmt.Errorf("%q is not a directory", dir)
}
c := &FileClient{dir: dir}
c.base = &ParseClient{GetFunc: c.get}
return c, nil
}
func (c *FileClient) get(dev device, filename string) (string, error) {
// TODO: support other devices
if dev != MD {
return "", fmt.Errorf("%s device not supported", dev)
}
b, err := ioutil.ReadFile(path.Join(c.dir, filename))
if err != nil {
return "", err
}
return string(b), nil
}
func (c *FileClient) Errors() ([]Error, error) {
return c.base.Errors()
}
func (c *FileClient) Frames() ([]Frame, error) {
return c.base.Frames()
}
func (c *FileClient) IO(types ...Type) ([]IO, error) {
return c.base.IO(types...)
}
func (c *FileClient) NumericRegisters() ([]NumericRegister, error) {
return c.base.NumericRegisters()
}
func (c *FileClient) PositionRegisters() ([]PositionRegister, error) {
return c.base.PositionRegisters()
}
func (c *FileClient) TPPrograms() ([]string, error) {
return c.base.TPPrograms()
}
func (c *FileClient) TPPositions(programName string) ([]Position, error) {
return c.base.TPPositions(programName)
}