From 86b1d958c0dc7cc42f814d4f86d8d95b2038aae5 Mon Sep 17 00:00:00 2001 From: Jamie Sinn Date: Tue, 8 Aug 2023 11:51:50 -0400 Subject: [PATCH 1/2] Expose raw config function --- client.go | 11 ++++++++++- configmanager.go | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 3ec951d5..df24733e 100644 --- a/client.go +++ b/client.go @@ -52,7 +52,6 @@ type Client struct { eventQueue *EventManager localBucketing LocalBucketing platformData *PlatformData - // Set to true when the client has been initialized, regardless of whether the config has loaded successfully. isInitialized bool internalOnInitializedChannel chan bool @@ -171,6 +170,16 @@ func (c *Client) generateBucketedConfig(user User) (config *BucketedUserConfig, return } +func (c *Client) GetRawConfig() (config []byte, err error) { + if c.configManager == nil { + return nil, errors.New("cannot read raw config; config manager is nil") + } + if c.configManager.HasConfig() { + return c.configManager.rawConfig, nil + } + return nil, errors.New("cannot read raw config; config manager has no config") +} + func createNullableString(val string) *proto.NullableString { if val == "" { return &proto.NullableString{Value: "", IsNull: true} diff --git a/configmanager.go b/configmanager.go index 03b435b8..2fb8736f 100644 --- a/configmanager.go +++ b/configmanager.go @@ -20,6 +20,7 @@ type ConfigReceiver interface { type EnvironmentConfigManager struct { sdkKey string + rawConfig []byte configETag string localBucketing ConfigReceiver firstLoad bool @@ -166,8 +167,9 @@ func (e *EnvironmentConfigManager) setConfig(config []byte, eTag string) error { if err != nil { return err } - + e.rawConfig = config e.hasConfig.Store(true) + return nil } From f878b5c6fdf254da2efc12d223bcdf9591c41a3a Mon Sep 17 00:00:00 2001 From: Jamie Sinn Date: Tue, 8 Aug 2023 12:06:07 -0400 Subject: [PATCH 2/2] Expose etag too. --- client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index df24733e..8c6e73bb 100644 --- a/client.go +++ b/client.go @@ -170,14 +170,14 @@ func (c *Client) generateBucketedConfig(user User) (config *BucketedUserConfig, return } -func (c *Client) GetRawConfig() (config []byte, err error) { +func (c *Client) GetRawConfig() (config []byte, etag string, err error) { if c.configManager == nil { - return nil, errors.New("cannot read raw config; config manager is nil") + return nil, "", errors.New("cannot read raw config; config manager is nil") } if c.configManager.HasConfig() { - return c.configManager.rawConfig, nil + return c.configManager.rawConfig, c.configManager.configETag, nil } - return nil, errors.New("cannot read raw config; config manager has no config") + return nil, "", errors.New("cannot read raw config; config manager has no config") } func createNullableString(val string) *proto.NullableString {