github.com/ladydascalie/elvish@v0.0.0-20170703214355-2964dd3ece7f/daemon/api/api.go (about) 1 // Package API provides the API to the daemon RPC service. 2 package api 3 4 import "github.com/elves/elvish/store/storedefs" 5 6 const ( 7 // ServiceName is the name of the RPC service exposed by the daemon. 8 ServiceName = "Daemon" 9 10 // Version is the API version. It should be bumped any time the API changes. 11 Version = -97 12 ) 13 14 // Basic requests. 15 16 type VersionRequest struct{} 17 18 type VersionResponse struct { 19 Version int 20 } 21 22 func (c *Client) Version() (int, error) { 23 req := &VersionRequest{} 24 res := &VersionResponse{} 25 err := c.CallDaemon("Version", req, res) 26 return res.Version, err 27 } 28 29 type PidRequest struct{} 30 31 type PidResponse struct { 32 Pid int 33 } 34 35 func (c *Client) Pid() (int, error) { 36 req := &PidRequest{} 37 res := &PidResponse{} 38 err := c.CallDaemon("Pid", req, res) 39 return res.Pid, err 40 } 41 42 // Cmd requests. 43 44 type NextCmdSeqRequest struct{} 45 46 type NextCmdSeqResponse struct { 47 Seq int 48 } 49 50 func (c *Client) NextCmdSeq() (int, error) { 51 req := &NextCmdRequest{} 52 res := &NextCmdSeqResponse{} 53 err := c.CallDaemon("NextCmdSeq", req, res) 54 return res.Seq, err 55 } 56 57 type AddCmdRequest struct { 58 Text string 59 } 60 61 type AddCmdResponse struct { 62 Seq int 63 } 64 65 func (c *Client) AddCmd(text string) (int, error) { 66 req := &AddCmdRequest{text} 67 res := &AddCmdResponse{} 68 err := c.CallDaemon("AddCmd", req, res) 69 return res.Seq, err 70 } 71 72 type CmdRequest struct { 73 Seq int 74 } 75 76 type CmdResponse struct { 77 Text string 78 } 79 80 func (c *Client) Cmd(seq int) (string, error) { 81 req := &CmdRequest{seq} 82 res := &CmdResponse{} 83 err := c.CallDaemon("Cmd", req, res) 84 return res.Text, err 85 } 86 87 type CmdsRequest struct { 88 From int 89 Upto int 90 } 91 92 type CmdsResponse struct { 93 Cmds []string 94 } 95 96 func (c *Client) Cmds(from, upto int) ([]string, error) { 97 req := &CmdsRequest{from, upto} 98 res := &CmdsResponse{} 99 err := c.CallDaemon("Cmds", req, res) 100 return res.Cmds, err 101 } 102 103 type NextCmdRequest struct { 104 From int 105 Prefix string 106 } 107 108 type NextCmdResponse struct { 109 Seq int 110 Text string 111 } 112 113 func (c *Client) NextCmd(from int, prefix string) (int, string, error) { 114 req := &NextCmdRequest{from, prefix} 115 res := &NextCmdResponse{} 116 err := c.CallDaemon("NextCmd", req, res) 117 return res.Seq, res.Text, err 118 } 119 120 type PrevCmdRequest struct { 121 Upto int 122 Prefix string 123 } 124 125 type PrevCmdResponse struct { 126 Seq int 127 Text string 128 } 129 130 func (c *Client) PrevCmd(upto int, prefix string) (int, string, error) { 131 req := &PrevCmdRequest{upto, prefix} 132 res := &PrevCmdResponse{} 133 err := c.CallDaemon("PrevCmd", req, res) 134 return res.Seq, res.Text, err 135 } 136 137 // Dir requests. 138 139 type AddDirRequest struct { 140 Dir string 141 IncFactor float64 142 } 143 144 type AddDirResponse struct{} 145 146 func (c *Client) AddDir(dir string, incFactor float64) error { 147 req := &AddDirRequest{dir, incFactor} 148 res := &AddDirResponse{} 149 err := c.CallDaemon("AddDir", req, res) 150 return err 151 } 152 153 type DirsRequest struct { 154 Blacklist map[string]struct{} 155 } 156 157 type DirsResponse struct { 158 Dirs []storedefs.Dir 159 } 160 161 func (c *Client) Dirs(blacklist map[string]struct{}) ([]storedefs.Dir, error) { 162 req := &DirsRequest{blacklist} 163 res := &DirsResponse{} 164 err := c.CallDaemon("Dirs", req, res) 165 return res.Dirs, err 166 } 167 168 // SharedVar requests. 169 170 type SharedVarRequest struct { 171 Name string 172 } 173 174 type SharedVarResponse struct { 175 Value string 176 } 177 178 func (c *Client) SharedVar(name string) (string, error) { 179 req := &SharedVarRequest{name} 180 res := &SharedVarResponse{} 181 err := c.CallDaemon("SharedVar", req, res) 182 return res.Value, err 183 } 184 185 type SetSharedVarRequest struct { 186 Name string 187 Value string 188 } 189 190 type SetSharedVarResponse struct{} 191 192 func (c *Client) SetSharedVar(name, value string) error { 193 req := &SetSharedVarRequest{name, value} 194 res := &SetSharedVarResponse{} 195 return c.CallDaemon("SetSharedVar", req, res) 196 } 197 198 type DelSharedVarRequest struct { 199 Name string 200 } 201 202 type DelSharedVarResponse struct{} 203 204 func (c *Client) DelSharedVar(name string) error { 205 req := &DelSharedVarRequest{} 206 res := &DelSharedVarResponse{} 207 return c.CallDaemon("DelSharedVar", req, res) 208 }