@@ -25,6 +25,8 @@ properties for distributed applications centrally.
2525
2626## Installation
2727
28+ The current version of this SDK: 0.1.0
29+
2830There are a few different ways to download and install the IBM App Configuration Go SDK project for use by your Go
2931application:
3032
@@ -55,7 +57,10 @@ Initialize the sdk to connect with your App Configuration service instance.
5557``` go
5658appConfiguration := AppConfiguration .GetInstance ()
5759appConfiguration.Init (" region" , " guid" , " apikey" )
58- appConfiguration.SetContext (" collectionId" , " environmentId" )
60+
61+ collectionId := " airlines-webapp"
62+ environmentId := " dev"
63+ appConfiguration.SetContext (collectionId, environmentId)
5964```
6065
6166- region : Region name where the App Configuration service instance is created. Use
@@ -78,37 +83,42 @@ You can also work offline with local configuration file and perform feature and
7883After [ ` appConfiguration.Init("region", "guid", "apikey") ` ] ( #using-the-sdk ) , follow the below steps
7984
8085``` go
81- appConfiguration.SetContext (" collectionId " , " environmentId " , AppConfiguration .ContextOptions {
82- ConfigurationFile : " path/to/configuration/file .json" ,
83- LiveConfigUpdateEnabled : false ,
86+ appConfiguration.SetContext (" airlines-webapp " , " dev " , AppConfiguration .ContextOptions {
87+ ConfigurationFile : " saflights/flights .json" ,
88+ LiveConfigUpdateEnabled : false
8489})
8590```
8691
8792- ConfigurationFile: Path to the JSON file, which contains configuration details.
8893- LiveConfigUpdateEnabled: Set this value to ` false ` if the new configuration values shouldn't be fetched from the
8994 server. Make sure to provide a proper JSON file in the path. By default, this value is enabled.
9095
96+ ### Permissions required by SDK
97+ Add write permission for ` non-root ` users to ` appconfiguration.json ` file which is used as cache in AppConfiguration SDK.
98+ AppConfiguration cache location will be the application root folder.
99+
91100## Get single feature
92101
93102``` go
94- feature := appConfiguration.GetFeature (" featureId" )
103+ feature , err := appConfiguration.GetFeature (" online-check-in" )
104+ if err == nil {
105+ fmt.Println (" Feature Name" , feature.GetFeatureName ())
106+ fmt.Println (" Feature Id" , feature.GetFeatureId ())
107+ fmt.Println (" Feature Type" , feature.GetFeatureDataType ())
95108
96- if (feature.IsEnabled ()) {
109+ if (feature.IsEnabled ()) {
97110 // feature flag is enabled
98- } else {
111+ } else {
99112 // feature flag is disabled
113+ }
100114}
101- fmt.Println (" Feature Name" , feature.GetFeatureName ())
102- fmt.Println (" Feature Id" , feature.GetFeatureId ())
103- fmt.Println (" Feature Type" , feature.GetFeatureDataType ())
104- fmt.Println (" Feature is enabled" , feature.IsEnabled ())
105115```
106116
107117## Get all features
108118
109119``` go
110120features := appConfiguration.GetFeatures ()
111- feature := features[" featureId " ]
121+ feature := features[" online-check-in " ]
112122
113123fmt.Println (" Feature Name" , feature.GetFeatureName ())
114124fmt.Println (" Feature Id" , feature.GetFeatureId ())
@@ -118,34 +128,35 @@ fmt.Println("Feature is enabled", feature.IsEnabled())
118128
119129## Evaluate a feature
120130
121- You can use the ` feature.GetCurrentValue(identityId, identityAttributes ) ` method to evaluate the value of the feature
122- flag. You should pass an unique identityId as the parameter to perform the feature flag evaluation. If the feature flag
131+ You can use the ` feature.GetCurrentValue(entityId, entityAttributes ) ` method to evaluate the value of the feature
132+ flag. You should pass an unique entityId as the parameter to perform the feature flag evaluation. If the feature flag
123133is configured with segments in the App Configuration service, you can set the attributes values as a map.
124134
125135``` go
126- identityId := " identityId "
127- identityAttributes := make (map [string ]interface {})
128- identityAttributes[ " email " ] = " ibm.com "
129- identityAttributes[ " city " ] = " Bangalore "
136+ entityId := " john_doe "
137+ entityAttributes := make (map [string ]interface {})
138+ entityAttributes[ " city " ] = " Bangalore "
139+ entityAttributes[ " country " ] = " India "
130140
131- featureVal := feature.GetCurrentValue (identityId, identityAttributes )
141+ featureVal := feature.GetCurrentValue (entityId, entityAttributes )
132142```
133143
134144## Get single property
135145
136146``` go
137- property := appConfiguration.GetProperty (" propertyId" )
138-
139- fmt.Println (" Property Name" , property.GetPropertyName ())
140- fmt.Println (" Property Id" , property.GetPropertyId ())
141- fmt.Println (" Property Type" , property.GetPropertyDataType ())
147+ property , err := appConfiguration.GetProperty (" check-in-charges" )
148+ if err == nil {
149+ fmt.Println (" Property Name" , property.GetPropertyName ())
150+ fmt.Println (" Property Id" , property.GetPropertyId ())
151+ fmt.Println (" Property Type" , property.GetPropertyDataType ())
152+ }
142153```
143154
144155## Get all properties
145156
146157``` go
147158properties := appConfiguration.GetProperties ()
148- property := properties[" propertyId " ]
159+ property := properties[" check-in-charges " ]
149160
150161fmt.Println (" Property Name" , property.GetPropertyName ())
151162fmt.Println (" Property Id" , property.GetPropertyId ())
@@ -154,22 +165,22 @@ fmt.Println("Property Type", property.GetPropertyDataType())
154165
155166## Evaluate a property
156167
157- You can use the ` property.GetCurrentValue(identityId, identityAttributes ) ` method to evaluate the value of the
158- property. You should pass an unique identityId as the parameter to perform the property evaluation. If the property is
168+ You can use the ` property.GetCurrentValue(entityId, entityAttributes ) ` method to evaluate the value of the
169+ property. You should pass an unique entityId as the parameter to perform the property evaluation. If the property is
159170configured with segments in the App Configuration service, you can set the attributes values as a map.
160171
161172``` go
162- identityId := " identityId "
163- identityAttributes := make (map [string ]interface {})
164- identityAttributes[ " email " ] = " ibm.com "
165- identityAttributes[ " city " ] = " Bengaluru "
173+ entityId := " john_doe "
174+ entityAttributes := make (map [string ]interface {})
175+ entityAttributes[ " city " ] = " Bangalore "
176+ entityAttributes[ " country " ] = " India "
166177
167- propertyVal := property.GetCurrentValue (identityId, identityAttributes )
178+ propertyVal := property.GetCurrentValue (entityId, entityAttributes )
168179```
169180
170181## Set listener for feature or property data changes
171182
172- To listen to the data changes add the following code in your application
183+ To listen to the configurations changes in your App Configuration service instance, implement the ` RegisterConfigurationUpdateListener ` event listener as mentioned below
173184
174185``` go
175186appConfiguration.RegisterConfigurationUpdateListener (func () {
0 commit comments