Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/common-go/experiments/experimentstest/client.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package experimentstest
6
7
import (
8
"context"
9
10
"github.com/gitpod-io/gitpod/common-go/experiments"
11
)
12
13
type Client struct {
14
BoolMatcher func(ctx context.Context, experiment string, defaultValue bool, attributes experiments.Attributes) bool
15
IntMatcher func(ctx context.Context, experimentName string, defaultValue int, attributes experiments.Attributes) int
16
FloatMatcher func(ctx context.Context, experimentName string, defaultValue float64, attributes experiments.Attributes) float64
17
StringMatcher func(ctx context.Context, experimentName string, defaultValue string, attributes experiments.Attributes) string
18
}
19
20
func (c *Client) GetBoolValue(ctx context.Context, experimentName string, defaultValue bool, attributes experiments.Attributes) bool {
21
if c.BoolMatcher == nil {
22
return defaultValue
23
}
24
return c.BoolMatcher(ctx, experimentName, defaultValue, attributes)
25
}
26
func (c *Client) GetIntValue(ctx context.Context, experimentName string, defaultValue int, attributes experiments.Attributes) int {
27
if c.IntMatcher == nil {
28
return defaultValue
29
}
30
return c.IntMatcher(ctx, experimentName, defaultValue, attributes)
31
}
32
func (c *Client) GetFloatValue(ctx context.Context, experimentName string, defaultValue float64, attributes experiments.Attributes) float64 {
33
if c.FloatMatcher == nil {
34
return defaultValue
35
}
36
return c.FloatMatcher(ctx, experimentName, defaultValue, attributes)
37
}
38
func (c *Client) GetStringValue(ctx context.Context, experimentName string, defaultValue string, attributes experiments.Attributes) string {
39
if c.StringMatcher == nil {
40
return defaultValue
41
}
42
return c.StringMatcher(ctx, experimentName, defaultValue, attributes)
43
}
44
45