Welcome to mirror list, hosted at ThFree Co, Russian Federation.

feature.go « feature « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9df43aa8d0bf13c252ec17cc5b3e7e7212e9520 (plain)
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
package feature

import "os"

type Feature struct {
	EnvVariable    string
	defaultEnabled bool
}

// RedirectsPlaceholders enables support for placeholders in redirects file
// TODO: remove https://gitlab.com/gitlab-org/gitlab-pages/-/issues/620
var RedirectsPlaceholders = Feature{
	EnvVariable:    "FF_ENABLE_PLACEHOLDERS",
	defaultEnabled: true,
}

// HandleReadErrors reports vfs.ReadErrors to sentry and enable error handling
var HandleReadErrors = Feature{
	EnvVariable: "FF_HANDLE_READ_ERRORS",
}

// ConfigurableRoot enables a project's root directory to be customized using
// the GitLab API
var ConfigurableRoot = Feature{
	EnvVariable: "FF_CONFIGURABLE_ROOT_DIR",
}

// Enabled reads the environment variable responsible for the feature flag
// if FF is disabled by default, the environment variable needs to be "true" to explicitly enable it
// if FF is enabled by default, variable needs to be "false" to explicitly disable it
func (f Feature) Enabled() bool {
	env := os.Getenv(f.EnvVariable)

	if f.defaultEnabled {
		return env != "false"
	}

	return env == "true"
}