...

Source file src/github.com/launchdarkly/go-server-sdk/v6/ldfiledata/package_info.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/ldfiledata

     1  // Package ldfiledata allows the LaunchDarkly client to read feature flag data from a file.
     2  //
     3  // This is different from [github.com/launchdarkly/go-server-sdk/v6/ldtestdata.DataSource], which
     4  // allows you to simulate flag configurations programmatically rather than using a file.
     5  //
     6  // To use the file-based data source in your SDK configuration, call ldfiledata.[DataSource] to obtain a
     7  // configurable object that you will use as the configuration's DataSource:
     8  //
     9  //	config := ld.Config{
    10  //	    DataSource: ldfiledata.DataSource()
    11  //	        .FilePaths("./test-data/my-flags.json"),
    12  //	}
    13  //	client := ld.MakeCustomClient(mySdkKey, config, 5*time.Second)
    14  //
    15  // Use FilePaths to specify any number of file paths. The files are not actually loaded until the
    16  // client starts up. At that point, if any file does not exist or cannot be parsed, the data source
    17  // will log an error and will not load any data.
    18  //
    19  // Files may contain either JSON or YAML; if the first non-whitespace character is '{', the file is parsed
    20  // as JSON, otherwise it is parsed as YAML. The file data should consist of an object with up to three
    21  // properties:
    22  //   - "flags": Feature flag definitions.
    23  //   - "flagValues": Simplified feature flags that contain only a value.
    24  //   - "segments": User segment definitions.
    25  //
    26  // The format of the data in "flags" and "segments" is defined by the LaunchDarkly application and is
    27  // subject to change. Rather than trying to construct these objects yourself, it is simpler to request
    28  // existing flags directly from the LaunchDarkly server in JSON format, and use this output as the starting
    29  // point for your file. In Linux you would do this:
    30  //
    31  //	curl -H "Authorization: <your sdk key>" https://app.launchdarkly.com/sdk/latest-all
    32  //
    33  // The output will look something like this (but with many more properties):
    34  //
    35  //	{
    36  //	  "flags": {
    37  //	    "flag-key-1": {
    38  //	      "key": "flag-key-1",
    39  //	      "on": true,
    40  //	      "variations": [ "a", "b" ]
    41  //	    }
    42  //	  },
    43  //	  "segments": {
    44  //	    "segment-key-1": {
    45  //	      "key": "segment-key-1",
    46  //	      "includes": [ "user-key-1" ]
    47  //	    }
    48  //	  }
    49  //	}
    50  //
    51  // Data in this format allows the SDK to exactly duplicate all the kinds of flag behavior supported by
    52  // LaunchDarkly. However, in many cases you will not need this complexity, but will just want to set
    53  // specific flag keys to specific values. For that, you can use a much simpler format:
    54  //
    55  //	{
    56  //	  "flagValues": {
    57  //	    "my-string-flag-key": "value-1",
    58  //	    "my-boolean-flag-key": true,
    59  //	    "my-integer-flag-key": 3
    60  //	  }
    61  //	}
    62  //
    63  // Or, in YAML:
    64  //
    65  //	flagValues:
    66  //	  my-string-flag-key: "value-1"
    67  //	  my-boolean-flag-key: true
    68  //	  my-integer-flag-key: 3
    69  //
    70  // It is also possible to specify both "flags" and "flagValues", if you want some flags to have simple
    71  // values and others to have complex behavior. However, it is an error to use the same flag key or
    72  // segment key more than once, either in a single file or across multiple files, unless you specify
    73  // otherwise with the DuplicateKeysHandling method.
    74  //
    75  // If the data source encounters any error in any file-- malformed content, a missing file, or a
    76  // duplicate key-- it will not load flags from any of the files.
    77  package ldfiledata
    78  

View as plain text