diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ipc/handler.go | 8 | ||||
-rw-r--r-- | lib/ipc/receive.go | 12 |
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/ipc/handler.go b/lib/ipc/handler.go new file mode 100644 index 00000000..fb8f0e06 --- /dev/null +++ b/lib/ipc/handler.go @@ -0,0 +1,8 @@ +package ipc + +import "net/url" + +type Handler interface { + Mailto(addr *url.URL) error + Mbox(source string) error +} diff --git a/lib/ipc/receive.go b/lib/ipc/receive.go index 11a96e30..0745e3d6 100644 --- a/lib/ipc/receive.go +++ b/lib/ipc/receive.go @@ -17,12 +17,10 @@ import ( type AercServer struct { listener net.Listener - - OnMailto func(addr *url.URL) error - OnMbox func(source string) error + handler Handler } -func StartServer() (*AercServer, error) { +func StartServer(handler Handler) (*AercServer, error) { sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock") // remove the socket if it is not connected to a session if err := ConnectAndExec(nil); err != nil { @@ -33,7 +31,7 @@ func StartServer() (*AercServer, error) { if err != nil { return nil, err } - as := &AercServer{listener: l} + as := &AercServer{listener: l, handler: handler} go as.Serve() return as, nil @@ -107,14 +105,14 @@ func (as *AercServer) handleMessage(req *Request) *Response { if err != nil { return &Response{Error: err.Error()} } - err = as.OnMailto(mailto) + err = as.handler.Mailto(mailto) if err != nil { return &Response{ Error: err.Error(), } } case strings.HasPrefix(req.Arguments[0], "mbox:"): - err = as.OnMbox(req.Arguments[0]) + err = as.handler.Mbox(req.Arguments[0]) if err != nil { return &Response{Error: err.Error()} } |