config

package
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 13 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtModVer

func FmtModVer(mod, ver string) string

FmtModVer is a helper function that can take pkg/a/b and v2.3.1 and returns pkg/a/b@v2.3.1.

func GetTimeoutDuration added in v0.3.0

func GetTimeoutDuration(timeout int) time.Duration

GetTimeoutDuration returns the timeout as time.duration.

func ModuleVersionFromPath added in v0.3.0

func ModuleVersionFromPath(path string) (string, string)

ModuleVersionFromPath returns module and version from a storage path. E.g athens/@v/v1.0.info -> athens and v.1.0.

func PackageVersionedName

func PackageVersionedName(module, version, ext string) string

PackageVersionedName return package full name used in storage. E.g athens/@v/v1.0.mod.

Types

type AzureBlobConfig added in v0.3.0

type AzureBlobConfig struct {
	AccountName               string `envconfig:"ATHENS_AZURE_ACCOUNT_NAME"                 validate:"required"`
	AccountKey                string `envconfig:"ATHENS_AZURE_ACCOUNT_KEY"`
	ManagedIdentityResourceID string `envconfig:"ATHENS_AZURE_MANAGED_IDENTITY_RESOURCE_ID"`
	CredentialScope           string `envconfig:"ATHENS_AZURE_CREDENTIAL_SCOPE"`
	ContainerName             string `envconfig:"ATHENS_AZURE_CONTAINER_NAME"               validate:"required"`
}

AzureBlobConfig specifies the properties required to use Azure as the storage backend.

type Config added in v0.2.0

type Config struct {
	TimeoutConf

	GoEnv                 string    `envconfig:"GO_ENV"                         validate:"required"`
	GoBinary              string    `envconfig:"GO_BINARY_PATH"                 validate:"required"`
	GoBinaryEnvVars       EnvList   `envconfig:"ATHENS_GO_BINARY_ENV_VARS"`
	GoGetWorkers          int       `envconfig:"ATHENS_GOGET_WORKERS"           validate:"required"`
	GoGetDir              string    `envconfig:"ATHENS_GOGET_DIR"`
	ProtocolWorkers       int       `envconfig:"ATHENS_PROTOCOL_WORKERS"        validate:"required"`
	LogLevel              string    `envconfig:"ATHENS_LOG_LEVEL"               validate:"required"`
	LogFormat             string    `envconfig:"ATHENS_LOG_FORMAT"              validate:"oneof='' 'json' 'plain'"`
	CloudRuntime          string    `envconfig:"ATHENS_CLOUD_RUNTIME"           validate:"required_without=LogFormat"`
	EnablePprof           bool      `envconfig:"ATHENS_ENABLE_PPROF"`
	PprofPort             string    `envconfig:"ATHENS_PPROF_PORT"`
	FilterFile            string    `envconfig:"ATHENS_FILTER_FILE"`
	TraceExporterURL      string    `envconfig:"ATHENS_TRACE_EXPORTER_URL"`
	TraceExporter         string    `envconfig:"ATHENS_TRACE_EXPORTER"`
	TraceSamplingFraction float64   `envconfig:"ATHENS_TRACE_SAMPLING_FRACTION"`
	StatsExporter         string    `envconfig:"ATHENS_STATS_EXPORTER"`
	StorageType           string    `envconfig:"ATHENS_STORAGE_TYPE"            validate:"required"`
	GlobalEndpoint        string    `envconfig:"ATHENS_GLOBAL_ENDPOINT"` // This feature is not yet implemented
	Port                  string    `envconfig:"ATHENS_PORT"`
	UnixSocket            string    `envconfig:"ATHENS_UNIX_SOCKET"`
	BasicAuthUser         string    `envconfig:"BASIC_AUTH_USER"`
	BasicAuthPass         string    `envconfig:"BASIC_AUTH_PASS"`
	HomeTemplatePath      string    `envconfig:"ATHENS_HOME_TEMPLATE_PATH"`
	ForceSSL              bool      `envconfig:"PROXY_FORCE_SSL"`
	ValidatorHook         string    `envconfig:"ATHENS_PROXY_VALIDATOR"`
	PathPrefix            string    `envconfig:"ATHENS_PATH_PREFIX"`
	NETRCPath             string    `envconfig:"ATHENS_NETRC_PATH"`
	GithubToken           string    `envconfig:"ATHENS_GITHUB_TOKEN"`
	HGRCPath              string    `envconfig:"ATHENS_HGRC_PATH"`
	TLSCertFile           string    `envconfig:"ATHENS_TLSCERT_FILE"`
	TLSKeyFile            string    `envconfig:"ATHENS_TLSKEY_FILE"`
	SumDBs                []string  `envconfig:"ATHENS_SUM_DBS"`
	NoSumPatterns         []string  `envconfig:"ATHENS_GONOSUM_PATTERNS"`
	DownloadMode          mode.Mode `envconfig:"ATHENS_DOWNLOAD_MODE"`
	DownloadURL           string    `envconfig:"ATHENS_DOWNLOAD_URL"`
	NetworkMode           string    `envconfig:"ATHENS_NETWORK_MODE"            validate:"oneof=strict offline fallback"`
	SingleFlightType      string    `envconfig:"ATHENS_SINGLE_FLIGHT_TYPE"`
	RobotsFile            string    `envconfig:"ATHENS_ROBOTS_FILE"`
	IndexType             string    `envconfig:"ATHENS_INDEX_TYPE"`
	ShutdownTimeout       int       `envconfig:"ATHENS_SHUTDOWN_TIMEOUT"        validate:"min=0"`
	StashTimeout          int       `envconfig:"ATHENS_STASH_TIMEOUT"`
	SingleFlight          *SingleFlight
	Storage               *Storage
	Index                 *Index
}

Config provides configuration values for all components.

func GetConf added in v0.2.0

func GetConf(path string) (*Config, error)

GetConf accepts the path to a file, constructs an absolute path to the file, and attempts to parse it into a Config struct.

func Load added in v0.3.0

func Load(configFile string) (*Config, error)

Load loads the config from a file. If file is not present returns default config.

func ParseConfigFile added in v0.2.0

func ParseConfigFile(configFile string) (*Config, error)

ParseConfigFile parses the given file into an athens config struct.

func (*Config) BasicAuth added in v0.2.0

func (c *Config) BasicAuth() (user, pass string, ok bool)

BasicAuth returns BasicAuthUser and BasicAuthPassword and ok if neither of them are empty.

func (*Config) FilterOff added in v0.2.0

func (c *Config) FilterOff() bool

FilterOff returns true if the FilterFile is empty.

func (*Config) StashTimeoutDuration added in v0.17.0

func (c *Config) StashTimeoutDuration() time.Duration

StashTimeoutDuration returns the stash timeout as time.Duration.

type DiskConfig added in v0.2.0

type DiskConfig struct {
	RootPath string `envconfig:"ATHENS_DISK_STORAGE_ROOT" validate:"required"`
}

DiskConfig specifies the properties required to use Disk as the storage backend.

type EnvList added in v0.6.1

type EnvList []string

EnvList is a list of key-value environment variables that are passed to the Go command.

func (*EnvList) Add added in v0.6.1

func (el *EnvList) Add(key, value string)

Add adds a key=value entry to the environment list.

func (*EnvList) Decode added in v0.7.2

func (el *EnvList) Decode(value string) error

Decode implements envconfig.Decoder. Please see the below link for more information on that interface:

https://github.com/kelseyhightower/envconfig#custom-decoders

We are doing this to allow for very long lists of assignments to be set inside of a single environment variable. For example:

ATHENS_GO_BINARY_ENV_VARS="GOPRIVATE=*.corp.example.com,rsc.io/private; GOPROXY=direct"

See the below link for more information: https://github.com/gomods/athens/issues/1404

func (EnvList) HasKey added in v0.6.1

func (el EnvList) HasKey(key string) bool

HasKey returns whether a key-value entry is present by only checking the left of key=value.

func (EnvList) Validate added in v0.6.1

func (el EnvList) Validate() error

Validate validates that all strings inside the list are of the key=value format.

type Etcd added in v0.3.0

type Etcd struct {
	Endpoints string `envconfig:"ATHENS_ETCD_ENDPOINTS"`
}

Etcd holds client side configuration that helps Athens connect to the Etcd backends.

type External added in v0.9.0

type External struct {
	URL string `envconfig:"ATHENS_EXTERNAL_STORAGE_URL" validate:"required"`
}

External specifies configuration for an external http storage.

type GCP added in v0.14.1

type GCP struct {
	StaleThreshold int `envconfig:"ATHENS_GCP_STALE_THRESHOLD"`
}

GCP is the configuration for GCP locking.

func DefaultGCPConfig added in v0.14.1

func DefaultGCPConfig() *GCP

DefaultGCPConfig returns the default GCP locking configuration.

type GCPConfig added in v0.2.0

type GCPConfig struct {
	ProjectID string `envconfig:"GOOGLE_CLOUD_PROJECT"`
	Bucket    string `envconfig:"ATHENS_STORAGE_GCP_BUCKET"   validate:"required"`
	JSONKey   string `envconfig:"ATHENS_STORAGE_GCP_JSON_KEY"`
}

GCPConfig specifies the properties required to use GCP as the storage backend.

type Index added in v0.10.0

type Index struct {
	MySQL    *MySQL
	Postgres *Postgres
}

Index is the config for various index storage backends.

type MinioConfig added in v0.2.0

type MinioConfig struct {
	Endpoint  string `envconfig:"ATHENS_MINIO_ENDPOINT"          validate:"required"`
	Key       string `envconfig:"ATHENS_MINIO_ACCESS_KEY_ID"     validate:"required"`
	Secret    string `envconfig:"ATHENS_MINIO_SECRET_ACCESS_KEY" validate:"required"`
	Bucket    string `envconfig:"ATHENS_MINIO_BUCKET_NAME"       validate:"required"`
	Region    string `envconfig:"ATHENS_MINIO_REGION"`
	EnableSSL bool   `envconfig:"ATHENS_MINIO_USE_SSL"`
}

MinioConfig specifies the properties required to use Minio or DigitalOcean Spaces as the storage backend.

type MongoConfig added in v0.2.0

type MongoConfig struct {
	URL                   string `envconfig:"ATHENS_MONGO_STORAGE_URL" validate:"required"`
	DefaultDBName         string `default:"athens"                     envconfig:"ATHENS_MONGO_DEFAULT_DATABASE"`
	DefaultCollectionName string `default:"modules"                    envconfig:"ATHENS_MONGO_DEFAULT_COLLECTION"`
	CertPath              string `envconfig:"ATHENS_MONGO_CERT_PATH"`
	InsecureConn          bool   `envconfig:"ATHENS_MONGO_INSECURE"`
}

MongoConfig specifies the properties required to use MongoDB as the storage backend.

type MySQL added in v0.10.0

type MySQL struct {
	Protocol string            `envconfig:"ATHENS_INDEX_MYSQL_PROTOCOL" validate:"required"`
	Host     string            `envconfig:"ATHENS_INDEX_MYSQL_HOST"     validate:"required"`
	Port     int               `envconfig:"ATHENS_INDEX_MYSQL_PORT"     validate:""`
	User     string            `envconfig:"ATHENS_INDEX_MYSQL_USER"     validate:"required"`
	Password string            `envconfig:"ATHENS_INDEX_MYSQL_PASSWORD" validate:""`
	Database string            `envconfig:"ATHENS_INDEX_MYSQL_DATABASE" validate:"required"`
	Params   map[string]string `envconfig:"ATHENS_INDEX_MYSQL_PARAMS"   validate:"required"`
}

MySQL config.

type Postgres added in v0.10.0

type Postgres struct {
	Host     string            `envconfig:"ATHENS_INDEX_POSTGRES_HOST"     validate:"required"`
	Port     int               `envconfig:"ATHENS_INDEX_POSTGRES_PORT"     validate:"required"`
	User     string            `envconfig:"ATHENS_INDEX_POSTGRES_USER"     validate:"required"`
	Password string            `envconfig:"ATHENS_INDEX_POSTGRES_PASSWORD" validate:""`
	Database string            `envconfig:"ATHENS_INDEX_POSTGRES_DATABASE" validate:"required"`
	Params   map[string]string `envconfig:"ATHENS_INDEX_POSTGRES_PARAMS"   validate:"required"`
}

Postgres config.

type Redis added in v0.4.0

type Redis struct {
	Endpoint   string `envconfig:"ATHENS_REDIS_ENDPOINT"`
	Password   string `envconfig:"ATHENS_REDIS_PASSWORD"`
	Cluster    bool   `envconfig:"ATHENS_REDIS_CLUSTER"`
	LockConfig *RedisLockConfig
}

Redis holds the client side configuration to connect to redis as a SingleFlight implementation.

type RedisLockConfig added in v0.12.0

type RedisLockConfig struct {
	Timeout    int `envconfig:"ATHENS_REDIS_LOCK_TIMEOUT"`
	TTL        int `envconfig:"ATHENS_REDIS_LOCK_TTL"`
	MaxRetries int `envconfig:"ATHENS_REDIS_LOCK_MAX_RETRIES"`
}

RedisLockConfig is the configuration for redis locking.

func DefaultRedisLockConfig added in v0.12.0

func DefaultRedisLockConfig() *RedisLockConfig

DefaultRedisLockConfig returns the default redis locking configuration.

type RedisSentinel added in v0.8.0

type RedisSentinel struct {
	Endpoints        []string `envconfig:"ATHENS_REDIS_SENTINEL_ENDPOINTS"`
	MasterName       string   `envconfig:"ATHENS_REDIS_SENTINEL_MASTER_NAME"`
	SentinelPassword string   `envconfig:"ATHENS_REDIS_SENTINEL_PASSWORD"`
	RedisUsername    string   `envconfig:"ATHENS_REDIS_USERNAME"`
	RedisPassword    string   `envconfig:"ATHENS_REDIS_PASSWORD"`
	DB               int      `envconfig:"ATHENS_REDIS_SENTINEL_DB"`
	LockConfig       *RedisLockConfig
}

RedisSentinel is the configuration for using redis with sentinel for SingleFlight.

type S3Config added in v0.2.0

type S3Config struct {
	Region                             string `envconfig:"AWS_REGION"                             validate:"required"`
	Key                                string `envconfig:"AWS_ACCESS_KEY_ID"`
	Secret                             string `envconfig:"AWS_SECRET_ACCESS_KEY"`
	Token                              string `envconfig:"AWS_SESSION_TOKEN"`
	Bucket                             string `envconfig:"ATHENS_S3_BUCKET_NAME"                  validate:"required"`
	UseDefaultConfiguration            bool   `envconfig:"AWS_USE_DEFAULT_CONFIGURATION"`
	ForcePathStyle                     bool   `envconfig:"AWS_FORCE_PATH_STYLE"`
	CredentialsEndpoint                string `envconfig:"AWS_CREDENTIALS_ENDPOINT"`
	AwsContainerCredentialsRelativeURI string `envconfig:"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"`
	Endpoint                           string `envconfig:"AWS_ENDPOINT"`
}

S3Config specifies the properties required to use S3 as the storage backend.

type SingleFlight added in v0.3.0

type SingleFlight struct {
	Etcd          *Etcd
	Redis         *Redis
	RedisSentinel *RedisSentinel
	GCP           *GCP
}

SingleFlight holds the various backend configurations for a distributed lock or single flight mechanism.

type Storage added in v0.10.0

type Storage struct {
	Disk      *DiskConfig
	GCP       *GCPConfig
	Minio     *MinioConfig
	Mongo     *MongoConfig
	S3        *S3Config
	AzureBlob *AzureBlobConfig
	External  *External
}

Storage provides configs for various storage backends.

type TimeoutConf added in v0.2.0

type TimeoutConf struct {
	Timeout int `validate:"required"`
}

TimeoutConf is a common struct for anything with a timeout.

func (*TimeoutConf) TimeoutDuration added in v0.2.0

func (t *TimeoutConf) TimeoutDuration() time.Duration

TimeoutDuration returns the timeout as time.duration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL