From 343aab7cd05cebbdcb2302b37b7cfc0349f9bee3 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Wed, 5 May 2021 17:43:01 -0700 Subject: [PATCH] added a client singelton to retereive the client object if it is lost --- bindings/client.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bindings/client.go b/bindings/client.go index 6eafdc35a..9274be190 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -25,6 +25,8 @@ import ( var extantClient bool var loginMux sync.Mutex +var clientSingleton *Client + // sets the log level func init() { jww.SetLogThreshold(jww.LevelInfo) @@ -96,7 +98,15 @@ func Login(storageDir string, password []byte, parameters string) (*Client, erro return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err)) } extantClient = true - return &Client{api: *client}, nil + clientSingleton :=&Client{api: *client} + return clientSingleton, nil +} + +// returns a previously created client. IF be used if the garbage collector +// removes the client instance on the app side. Is NOT thread safe relative to +// login, newClient, or newPrecannedClient +func GetClientSingleton() *Client { + return clientSingleton } // sets level of logging. All logs the set level and above will be displayed -- GitLab