From: Simon Ruderich Date: Tue, 18 May 2021 16:36:06 +0000 (+0200) Subject: frontend: add Loop.HostInfoMsg() X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=commitdiff_plain;h=09dd8f99fd8598b809f4d58d4a325310b555981f frontend: add Loop.HostInfoMsg() --- diff --git a/cmd/safcm/sync_info.go b/cmd/safcm/sync_info.go index 91878e8..8672a3e 100644 --- a/cmd/safcm/sync_info.go +++ b/cmd/safcm/sync_info.go @@ -28,17 +28,13 @@ import ( ) func (s *Sync) hostInfo(conn *rpc.Conn) ([]string, error) { - x, err := s.loop.SendRecv(s, conn, safcm.MsgInfoReq{ + resp, err := s.loop.HostInfoMsg(s, conn, safcm.MsgInfoReq{ LogLevel: s.config.LogLevel, DetectGroups: s.config.DetectGroups, }) if err != nil { return nil, err } - resp, ok := x.(safcm.MsgInfoResp) - if !ok { - return nil, fmt.Errorf("unexpected response %v", x) - } if resp.Error != "" { return nil, fmt.Errorf("%s", resp.Error) } diff --git a/frontend/conn.go b/frontend/conn.go index 10f7c7b..02dfe8b 100644 --- a/frontend/conn.go +++ b/frontend/conn.go @@ -18,6 +18,8 @@ package frontend import ( + "fmt" + "ruderich.org/simon/safcm" "ruderich.org/simon/safcm/rpc" ) @@ -45,3 +47,20 @@ func (l *Loop) SendRecv(host Host, conn *rpc.Conn, msg safcm.Msg) ( return x, nil } } + +// HostInfoMsg sends a MsgInfoReq for host via conn and returns the resulting +// MsgInfoResp. +func (l *Loop) HostInfoMsg(host Host, conn *rpc.Conn, req safcm.MsgInfoReq) ( + safcm.MsgInfoResp, error) { + + var empty safcm.MsgInfoResp + x, err := l.SendRecv(host, conn, req) + if err != nil { + return empty, err + } + resp, ok := x.(safcm.MsgInfoResp) + if !ok { + return empty, fmt.Errorf("unexpected response %v", x) + } + return resp, nil +}