Repository: Unleash/unleash-client-go (go)

Issue:
Add app & environment variant override support
### Describe the feature request

At the moment, the SDK doesn't support setting a variant override for `appName` / `environment` despite this being supported by Unleash. Only `userId`, `sessionId`, and `remoteAddress` are supported.

https://github.com/Unleash/unleash-client-go/blob/10a33385c5b131f72c4a179c6efadfeb55e13089/api/variant.go#L55

<img width="920" alt="Screenshot 2024-08-27 at 14 35 12" src="https://github.com/user-attachments/assets/c628dac9-b844-436c-9be5-6815a84a8789">

This is a trivial feature to support, I could open a PR but wasn't sure what the contribution guidelines are on this project.

### Background

_No response_

### Solution suggestions

Add cases for `appName` & `environment` to `Override.getIdentifier()` and return their values from the context.

Pull request description:
Feat: support environment and appName variant overrides
## About the changes
At the moment, the SDK doesn't support setting a variant override for appName / environment despite this being supported by Unleash. This PR adds `environment` and `appName` to `Override.getIdentifier()` to support setting them as variant overrides.

Closes #178

Patch:
diff --git a/api/variant.go b/api/variant.go
index 8211dd2..c92af76 100644
--- a/api/variant.go
+++ b/api/variant.go
@@ -61,6 +61,10 @@ func (o Override) getIdentifier(ctx *context.Context) string {
 		value = ctx.SessionId
 	case "remoteAddress":
 		value = ctx.RemoteAddress
+	case "environment":
+		value = ctx.Environment
+	case "appName":
+		value = ctx.AppName
 	default:
 		if len(ctx.Properties) > 0 {
 			for k, v := range ctx.Properties {


Test patch:
diff --git a/api/variant_test.go b/api/variant_test.go
index 770404b..e834f70 100644
--- a/api/variant_test.go
+++ b/api/variant_test.go
@@ -23,7 +23,7 @@ func (suite *VariantTestSuite) SetupTest() {
 					Value: "Test 1",
 				},
 			},
-			Weight: 33,
+			Weight: 25,
 			Overrides: []Override{
 				Override{
 					ContextName: "userId",
@@ -47,7 +47,7 @@ func (suite *VariantTestSuite) SetupTest() {
 					Value: "Test 2",
 				},
 			},
-			Weight: 33,
+			Weight: 25,
 			Overrides: []Override{
 				Override{
 					ContextName: "remoteAddress",
@@ -65,7 +65,7 @@ func (suite *VariantTestSuite) SetupTest() {
 					Value: "Test 3",
 				},
 			},
-			Weight: 34,
+			Weight: 25,
 			Overrides: []Override{
 				Override{
 					ContextName: "env",
@@ -75,6 +75,30 @@ func (suite *VariantTestSuite) SetupTest() {
 				},
 			},
 		},
+		VariantInternal{
+			Variant: Variant{
+				Name: "VarG",
+				Payload: Payload{
+					Type:  "string",
+					Value: "Test 4",
+				},
+			},
+			Weight: 25,
+			Overrides: []Override{
+				Override{
+					ContextName: "environment",
+					Values: []string{
+						"development",
+					},
+				},
+				Override{
+					ContextName: "appName",
+					Values: []string{
+						"test",
+					},
+				},
+			},
+		},
 	}
 
 	suite.VariantWithoutOverride = []VariantInternal{
@@ -263,3 +287,47 @@ func TestVariantSuite(t *testing.T) {
 	ts := VariantTestSuite{}
 	suite.Run(t, &ts)
 }
+
+func (suite *VariantTestSuite) TestGetVariant_OverrideOnAppName() {
+	mockFeature := Feature{
+		Name:     "test.variants",
+		Enabled:  true,
+		Variants: suite.VariantWithOverride,
+	}
+	mockContext := &context.Context{
+		AppName: "test",
+	}
+	expectedPayload := Payload{
+		Type:  "string",
+		Value: "Test 4",
+	}
+	variantSetup := VariantCollection{
+		GroupId:  mockFeature.Name,
+		Variants: mockFeature.Variants,
+	}.GetVariant(mockContext)
+	suite.Equal("VarG", variantSetup.Name, "Should return VarG")
+	suite.Equal(true, variantSetup.Enabled, "Should be equal")
+	suite.Equal(expectedPayload, variantSetup.Payload, "Should be equal")
+}
+
+func (suite *VariantTestSuite) TestGetVariant_OverrideOnEnvironment() {
+	mockFeature := Feature{
+		Name:     "test.variants",
+		Enabled:  true,
+		Variants: suite.VariantWithOverride,
+	}
+	mockContext := &context.Context{
+		Environment: "development",
+	}
+	expectedPayload := Payload{
+		Type:  "string",
+		Value: "Test 4",
+	}
+	variantSetup := VariantCollection{
+		GroupId:  mockFeature.Name,
+		Variants: mockFeature.Variants,
+	}.GetVariant(mockContext)
+	suite.Equal("VarG", variantSetup.Name, "Should return VarG")
+	suite.Equal(true, variantSetup.Enabled, "Should be equal")
+	suite.Equal(expectedPayload, variantSetup.Payload, "Should be equal")
+}