pkgsite: golang.org/x/pkgsite/internal/config Index | Files

package config

import "golang.org/x/pkgsite/internal/config"

Package config resolves shared configuration for Go Discovery services, and provides functions to access this configuration.

The Init function should be called before using any of the configuration accessors.

Index

Package Files

config.go

Constants

const AppVersionFormat = "20060102t150405"

AppVersionFormat is the expected format of the app version timestamp.

const AuthHeader = "X-Go-Discovery-Auth"

AuthHeader is the header key used by the frontend server to know that a request is coming from a known source.

const SourceTimeout = 1 * time.Minute

SourceTimeout is the value of the timeout for source.Client, which is used to fetch source code from third party URLs.

const StatementTimeout = 10 * time.Minute

StatementTimeout is the value of the Postgres statement_timeout parameter. Statements that run longer than this are terminated. 10 minutes is the App Engine standard request timeout.

const TaskIDChangeIntervalFrontend = 30 * time.Minute

TaskIDChangeIntervalFrontend is the time period during which a given module version can be re-enqueued to frontend tasks.

const TaskIDChangeIntervalWorker = 3 * time.Hour

TaskIDChangeIntervalWorker is the time period during which a given module version can be re-enqueued to fetch tasks.

func GetEnv Uses

func GetEnv(key, fallback string) string

GetEnv looks up the given key from the environment, returning its value if it exists, and otherwise returning the given fallback value.

func ValidateAppVersion Uses

func ValidateAppVersion(appVersion string) error

ValidateAppVersion validates that appVersion follows the expected format defined by AppVersionFormat.

type Config Uses

type Config struct {
    // AuthValues is the set of values that could be set on the AuthHeader, in
    // order to bypass checks by the cache.
    AuthValues []string

    // Discovery environment variables
    ProxyURL, IndexURL string

    // Ports used for hosting. 'DebugPort' is used for serving HTTP debug pages.
    Port, DebugPort string

    // AppEngine identifiers
    ProjectID, ServiceID, VersionID, ZoneID, InstanceID, LocationID string

    // QueueService is used to identify which service Cloud Tasks queue
    // should send requests to.
    QueueService string

    GaeEnv string

    // GoogleTagManagerID is the ID used for GoogleTagManager. It has the
    // structure GTM-XXXX.
    GoogleTagManagerID string

    // AppMonitoredResource is the resource for the current GAE app.
    // See https://cloud.google.com/monitoring/api/resources#tag_gae_app for more
    // details:
    // "An object representing a resource that can be used for monitoring, logging,
    // billing, or other purposes. Examples include virtual machine instances,
    // databases, and storage devices such as disks.""
    AppMonitoredResource *mrpb.MonitoredResource

    // FallbackVersionLabel is used as the VersionLabel when not hosting on
    // AppEngine.
    FallbackVersionLabel string

    DBSecret, DBUser, DBHost, DBPort, DBName string
    DBSecondaryHost                          string // DB host to use if first one is down
    DBPassword                               string `json:"-"`

    // Configuration for redis page cache.
    RedisCacheHost, RedisCachePort string

    // Configuration for redis autocompletion. This is different from the page
    // cache instance as it has different availability requirements.
    RedisHAHost, RedisHAPort string

    // UseProfiler specifies whether to enable Stackdriver Profiler.
    UseProfiler bool

    Quota QuotaSettings

    // TeeproxyAuthValue is the value set by the teeproxy header, so that
    // the frontend server knows the source of those requests.
    TeeproxyAuthValue string

    // TeeproxyTargetHosts is a list of hosts that teeproxy will forward
    // requests to.
    TeeproxyForwardedHosts []string
}

Config holds shared configuration values used in instantiating our server components.

func Init Uses

func Init(ctx context.Context) (_ *Config, err error)

Init resolves all configuration values provided by the config package. It must be called before any configuration values are used.

func (*Config) AppVersionLabel Uses

func (c *Config) AppVersionLabel() string

AppVersionLabel returns the version label for the current instance. This is the AppVersionID available, otherwise a string constructed using the timestamp of process start.

func (*Config) DBConnInfo Uses

func (c *Config) DBConnInfo() string

DBConnInfo returns a PostgreSQL connection string constructed from environment variables, using the primary database host.

func (*Config) DBSecondaryConnInfo Uses

func (c *Config) DBSecondaryConnInfo() string

DBSecondaryConnInfo returns a PostgreSQL connection string constructed from environment variables, using the backup database host. It returns the empty string if no backup is configured.

func (*Config) DebugAddr Uses

func (c *Config) DebugAddr(dflt string) string

DebugAddr returns the network address on which to serve debugging information.

func (*Config) Dump Uses

func (c *Config) Dump(w io.Writer) error

Dump outputs the current config information to the given Writer.

func (*Config) HostAddr Uses

func (c *Config) HostAddr(dflt string) string

HostAddr returns the network on which to serve the primary HTTP service.

func (*Config) OnAppEngine Uses

func (c *Config) OnAppEngine() bool

OnAppEngine reports if the current process is running in an AppEngine environment.

type QuotaSettings Uses

type QuotaSettings struct {
    QPS        int // allowed queries per second, per IP block
    Burst      int // maximum requests per second, per block; the size of the token bucket
    MaxEntries int // maximum number of entries to keep track of
    // Record data about blocking, but do not actually block.
    // This is a *bool, so we can distinguish "not present" from "false" in an override
    RecordOnly *bool
    // AuthValues is the set of values that could be set on the AuthHeader, in
    // order to bypass checks by the quota server.
    AuthValues []string
}

QuotaSettings is config for internal/middleware/quota.go

Package config imports 17 packages (graph) and is imported by 15 packages. Updated 2020-08-05. Refresh now. Tools for package owners.