Skip to content
Snippets Groups Projects
Commit 343aab7c authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

added a client singelton to retereive the client object if it is lost

parent e0f1c10e
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,8 @@ import ( ...@@ -25,6 +25,8 @@ import (
var extantClient bool var extantClient bool
var loginMux sync.Mutex var loginMux sync.Mutex
var clientSingleton *Client
// sets the log level // sets the log level
func init() { func init() {
jww.SetLogThreshold(jww.LevelInfo) jww.SetLogThreshold(jww.LevelInfo)
...@@ -96,7 +98,15 @@ func Login(storageDir string, password []byte, parameters string) (*Client, erro ...@@ -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)) return nil, errors.New(fmt.Sprintf("Failed to login: %+v", err))
} }
extantClient = true 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 // sets level of logging. All logs the set level and above will be displayed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment