This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/reach/reachview_version.go

50 lines
1.1 KiB
Go

package reach
import (
"sync"
"forge.cadoles.com/Pyxis/golang-socketio"
"github.com/pkg/errors"
)
const (
eventGetReachViewVersion = "get reachview version"
eventReachViewVersionResults = "current reachview version"
)
type reachViewVersion struct {
Version string `json:"version"`
}
// ReachViewVersion returns the ReachRS module ReachView version
func (c *Client) ReachViewVersion() (string, error) {
var err error
var version string
var wg sync.WaitGroup
wg.Add(1)
err = c.conn.On(eventReachViewVersionResults, func(h *gosocketio.Channel, rv *reachViewVersion) {
version = rv.Version
c.conn.Off(eventReachViewVersionResults)
wg.Done()
})
if err != nil {
return "", errors.Wrapf(err, "error while binding to '%s' event", eventReachViewVersionResults)
}
c.logf("sending '%s' event", eventGetReachViewVersion)
if err = c.conn.Emit(eventGetReachViewVersion, nil); err != nil {
return "", errors.Wrapf(err, "error while emitting '%s' event", eventGetReachViewVersion)
}
c.logf("'%s' event sent", eventGetReachViewVersion)
wg.Wait()
c.logf("reachview version result: %v", version)
return version, err
}