-
Notifications
You must be signed in to change notification settings - Fork 181
/
experiment.go
72 lines (61 loc) · 2.78 KB
/
experiment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package internal
import (
"context"
)
const (
ExperimentAutocomplete = "autocomplete"
ExperimentFrontendFetch = "frontend-fetch"
ExperimentMasterVersion = "master-version"
ExperimentExecutableExamples = "executable-examples"
ExperimentSidenav = "sidenav"
ExperimentTranslateHTML = "translate-html"
ExperimentUseDirectories = "use-directories"
ExperimentUsePackageImports = "use-package-imports"
ExperimentUsePathInfo = "use-path-info"
)
// Experiments represents all of the active experiments in the codebase and
// a description of each experiment.
var Experiments = map[string]string{
ExperimentAutocomplete: "Enable autocomplete with search.",
ExperimentFrontendFetch: "Enable ability to fetch a package that doesn't exist on pkg.go.dev.",
ExperimentMasterVersion: "Enable viewing path@master.",
ExperimentExecutableExamples: "Display executable examples with their import statements, so that they are runnable via the Go playground.",
ExperimentSidenav: "Display documentation index on the left sidenav.",
ExperimentTranslateHTML: "Parse HTML text in READMEs, to properly display images.",
ExperimentUseDirectories: "Read from paths, documentation, readmes, and package_imports tables.",
ExperimentUsePathInfo: "Check the paths table if a path exists, as opposed to the packages or modules table.",
ExperimentUsePackageImports: "Read imports from the package_imports table.",
}
// Experiment holds data associated with an experimental feature for frontend
// or worker.
type Experiment struct {
// Name is the name of the feature.
Name string
// Rollout is the percentage of requests enrolled in the experiment.
Rollout uint
// Description provides a description of the experiment.
Description string
}
// ExperimentSource is the interface used by the middleware to interact with
// experiments data.
type ExperimentSource interface {
// GetExperiments fetches active experiments from the
// ExperimentSource.
GetExperiments(ctx context.Context) ([]*Experiment, error)
}
// LocalExperimentSource is used when developing locally using the direct proxy
// mode.
type LocalExperimentSource struct {
experiments []*Experiment
}
// NewLocalExperimentSource returns a LocalExperimentSource with the provided experiments.
func NewLocalExperimentSource(experiments []*Experiment) *LocalExperimentSource {
return &LocalExperimentSource{experiments: experiments}
}
// GetExperiments returns the experiments for the given LocalExperimentSource.
func (e *LocalExperimentSource) GetExperiments(ctx context.Context) ([]*Experiment, error) {
return e.experiments, nil
}