diff --git a/cmd/statusd/library.go b/cmd/statusd/library.go index 22668809c..f65506b60 100644 --- a/cmd/statusd/library.go +++ b/cmd/statusd/library.go @@ -376,6 +376,25 @@ func makeJSONResponse(err error) *C.char { // Notify sends push notification by given token //export Notify func Notify(token *C.char) *C.char { - res := statusAPI.Notify(C.GoString(token)) - return C.CString(res) + err := statusAPI.Notify(C.GoString(token)) + + res := true + errString := "" + if err != nil { + res = false + errString = err.Error() + } + + out := common.NotifyResult{ + Status: res, + Error: errString, + } + + outBytes, err := json.Marshal(&out) + if err != nil { + log.Error("failed to marshal Notify output", "error", err.Error()) + return makeJSONResponse(err) + } + + return C.CString(string(outBytes)) } diff --git a/geth/api/api.go b/geth/api/api.go index 5ecfdad05..377a46a5f 100644 --- a/geth/api/api.go +++ b/geth/api/api.go @@ -195,7 +195,7 @@ func (api *StatusAPI) JailBaseJS(js string) { } // Notify and send message. -func (api *StatusAPI) Notify(token string) string { +func (api *StatusAPI) Notify(token string) error { log.Debug("Notify", "token", token) // TODO(oskarth): Experiment with this @@ -204,10 +204,10 @@ func (api *StatusAPI) Notify(token string) string { "sum": "Happy Day", } - err := api.b.notification.Notify(msg, token) + err := api.b.notifier().Notify(msg, token) if err != nil { log.Error("Notify failed:", err) } - return token + return err } diff --git a/geth/api/backend.go b/geth/api/backend.go index b47365f30..d52b25aa9 100644 --- a/geth/api/backend.go +++ b/geth/api/backend.go @@ -29,7 +29,7 @@ type StatusBackend struct { accountManager common.AccountManager txQueueManager common.TxQueueManager jailManager common.JailManager - notification common.Notifier + notifier common.NotifierConstructor } // NewStatusBackend create a new NewStatusBackend instance @@ -47,7 +47,7 @@ func NewStatusBackend() *StatusBackend { accountManager: accountManager, jailManager: jailManager, txQueueManager: txQueueManager, - notification: notificationManager, + notifier: notificationManager, } } diff --git a/geth/common/notification.go b/geth/common/notification.go index ead1c5462..dcd67ccd4 100644 --- a/geth/common/notification.go +++ b/geth/common/notification.go @@ -4,3 +4,6 @@ package common type Notifier interface { Notify(body interface{}, tokens ...string) error } + +// NotifierConstructor returns constructor of configured instance Notifier interface. +type NotifierConstructor func() Notifier diff --git a/geth/common/types.go b/geth/common/types.go index fe91c5327..1a7c9f884 100644 --- a/geth/common/types.go +++ b/geth/common/types.go @@ -395,6 +395,12 @@ type TestConfig struct { } } +// NotifyResult is a JSON returned from notify message +type NotifyResult struct { + Status bool `json:"status"` + Error string `json:"error"` +} + // LoadTestConfig loads test configuration values from disk func LoadTestConfig() (*TestConfig, error) { var testConfig TestConfig