-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(offline-mode): Add support for offline mode
- Loading branch information
1 parent
6e93e4e
commit 3506375
Showing
7 changed files
with
272 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"api_key": "B62qaMZNwfiqT76p38ggrQ", | ||
"project": { | ||
"name": "Test project", | ||
"organisation": { | ||
"feature_analytics": false, | ||
"name": "Test Org", | ||
"id": 1, | ||
"persist_trait_data": true, | ||
"stop_serving_flags": false | ||
}, | ||
"id": 1, | ||
"hide_disabled_flags": false, | ||
"segments": [ | ||
{ | ||
"id": 1, | ||
"name": "Test Segment", | ||
"feature_states": [], | ||
"rules": [ | ||
{ | ||
"type": "ALL", | ||
"conditions": [], | ||
"rules": [ | ||
{ | ||
"type": "ALL", | ||
"rules": [], | ||
"conditions": [ | ||
{ | ||
"operator": "EQUAL", | ||
"property_": "foo", | ||
"value": "bar" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"segment_overrides": [], | ||
"id": 1, | ||
"feature_states": [ | ||
{ | ||
"multivariate_feature_state_values": [], | ||
"feature_state_value": "some_value", | ||
"id": 1, | ||
"featurestate_uuid": "40eb539d-3713-4720-bbd4-829dbef10d51", | ||
"feature": { | ||
"name": "feature_1", | ||
"type": "STANDARD", | ||
"id": 1 | ||
}, | ||
"segment_id": null, | ||
"enabled": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package flagsmith | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/Flagsmith/flagsmith-go-client/v3/flagengine/environments" | ||
) | ||
|
||
type OfflineHandler interface { | ||
GetEnvironment() *environments.EnvironmentModel | ||
} | ||
|
||
type LocalFileHandler struct { | ||
environment *environments.EnvironmentModel | ||
} | ||
|
||
func NewLocalFileHandler(environmentDocumentPath string) (*LocalFileHandler, error) { | ||
// Read the environment document from the specified path | ||
environmentDocument, err := os.ReadFile(environmentDocumentPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var environment environments.EnvironmentModel | ||
if err := json.Unmarshal(environmentDocument, &environment); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Create and initialize the LocalFileHandler | ||
handler := &LocalFileHandler{ | ||
environment: &environment, | ||
} | ||
|
||
return handler, nil | ||
} | ||
|
||
func (handler *LocalFileHandler) GetEnvironment() *environments.EnvironmentModel { | ||
return handler.environment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package flagsmith_test | ||
|
||
import ( | ||
"testing" | ||
|
||
flagsmith "github.com/Flagsmith/flagsmith-go-client/v3" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewLocalFileHandler(t *testing.T) { | ||
// Given | ||
envJsonPath := "./fixtures/environment.json" | ||
|
||
// When | ||
offlineHandler, err := flagsmith.NewLocalFileHandler(envJsonPath) | ||
|
||
// Then | ||
assert.NoError(t, err) | ||
assert.NotNil(t, offlineHandler) | ||
|
||
} | ||
|
||
func TestLocalFileHandlerGetEnvironment(t *testing.T) { | ||
// Given | ||
envJsonPath := "./fixtures/environment.json" | ||
localHandler, err := flagsmith.NewLocalFileHandler(envJsonPath) | ||
|
||
assert.NoError(t, err) | ||
|
||
// When | ||
environment := localHandler.GetEnvironment() | ||
|
||
// Then | ||
assert.NotNil(t, environment.APIKey) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters