From 38c9cdacceb2400fe3695d15a604f8ab36a5ecfb Mon Sep 17 00:00:00 2001 From: Gagan Date: Fri, 30 Aug 2024 21:59:19 +0530 Subject: [PATCH] docs(offline-handler): Add docs for Rust and Go (#4540) --- docs/docs/clients/server-side.md | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/docs/docs/clients/server-side.md b/docs/docs/clients/server-side.md index 0996e7e0da20..b9647bebeeb2 100644 --- a/docs/docs/clients/server-side.md +++ b/docs/docs/clients/server-side.md @@ -876,6 +876,59 @@ class MyCustomOfflineHandler end ``` + + + +```rust +# Using the built-in local file handler + +let handler = offline_handler::LocalFileHandler::new("environment.json").unwrap(); + +# Instantiate the client with offline handler + + let flagsmith_options = FlagsmithOptions { + offline_handler: Some(Box::new(handler)), + ..Default::default() +}; + +let flagsmith = Flagsmith::new(ENVIRONMENT_KEY.to_string(), flagsmith_options); + + +# Defining a custom offline handler +impl OfflineHandler for MyCustomOfflineHandler { + fn get_environment(&self) -> Environment { + ... + } +} + +``` + + + + +```go +# Using the built-in local file handler + +envJsonPath := "./fixtures/environment.json" +offlineHandler, err := flagsmith.NewLocalFileHandler(envJsonPath) + +# Instantiate the client with offline handler + +flagsmith := flagsmith.NewClient(EnvironmentAPIKey, flagsmith.WithOfflineHandler(offlineHandler), + flagsmith.WithBaseURL(server.URL+"/api/v1/")) + + +# Defining a custom offline handler +type CustomOfflineHandler struct { + ... +} + +func (handler *CustomOfflineHandler) GetEnvironment() *environments.EnvironmentModel { + ... +} + +``` + @@ -1540,6 +1593,13 @@ client := flagsmith.NewClient(os.Getenv("FLAGSMITH_SERVER_SIDE_ENVIRONMENT_KEY") // response flagsmith.WithDefaultHandler(defaultFlagHandler), + // WithOfflineMode returns an Option function that enables the offline mode. + flagsmith.WithOfflineHandler(offlineHandler) + + // WithOfflineMode returns an Option function that enables the offline mode. + // (before using this option, you should set the offline handler) + flagsmith.WithOfflineMode() + // Allows the client to use any logger that implements the `Logger` interface. flagsmith.WithLogger(ctx), @@ -1592,6 +1652,12 @@ let options = FlagsmithOptions { // feature is Requested // Defaults to None default_flag_handler: None + + // Provide an offline handler to use with offline mode, or as a means of returning default flags + offline_handler: None + + // Set the SDK into offline mode(offline_handler must be set) + offline_mode: false }; // Required Arguments