diff options
author | Moritz Poldrack <git@moritz.sh> | 2023-03-04 10:56:46 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-07 00:12:55 +0100 |
commit | c6a08b1003a2cb02d86002541ead0f9b38db1beb (patch) | |
tree | 80dead95349d263b8bad20c17b6005b523367485 /lib | |
parent | 4838efdb1d5a746432a30ef0b86b090aab52fa7a (diff) | |
download | aerc-c6a08b1003a2cb02d86002541ead0f9b38db1beb.tar.gz |
ipc: use an interface instead of a function list
Currently, every function has to be mapped to the according handler with
our god-object. To make adding new handlers require less changes, change
this mapping into an interface that is satisfied by *widgets.Aerc
Signed-off-by: Moritz Poldrack <git@moritz.sh>
Signed-off-by: Robin Jarry <robin@jarry.cc>
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()} } |