constants

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Overview

Package constants provides centralized configuration constants for the gitlab-backup project.

This package consolidates all hard-coded values, timeouts, limits, and magic numbers from across the codebase into a single, well-documented source of truth.

Organization:

  • gitlab.go: GitLab API constants (rate limits, timeouts, endpoints)
  • storage.go: Storage constants (buffer sizes, file permissions)
  • validation.go: Validation constraints (AWS limits, config boundaries)
  • output.go: CLI output formatting constants

Modifying Constants: Most constants are based on external API limits (GitLab, AWS) or performance characteristics. Before modifying:

  1. Check the documentation comment for rationale
  2. Verify external API documentation (links provided)
  3. Test thoroughly with the new value
  4. Update related constants if needed

See each file for detailed documentation on specific constant groups.

Index

Constants

View Source
const (
	// GitLabAPIEndpoint is the default GitLab API endpoint for gitlab.com.
	// For self-managed GitLab instances, override via SetGitlabEndpoint().
	GitLabAPIEndpoint = "https://gitlab.com/api/v4"

	// GitLabBaseURL is the default GitLab base URL without API version.
	GitLabBaseURL = "https://gitlab.com"
)

GitLab API Endpoint.

View Source
const (
	// DownloadRateLimitIntervalSeconds is the time window for download rate limiting (60 seconds = 1 minute).
	DownloadRateLimitIntervalSeconds = 60

	// DownloadRateLimitBurst is the maximum number of download requests allowed per interval.
	// GitLab repository files API limit: 5 requests per minute per user.
	DownloadRateLimitBurst = 5

	// ExportRateLimitIntervalSeconds is the time window for export rate limiting (60 seconds = 1 minute).
	ExportRateLimitIntervalSeconds = 60

	// ExportRateLimitBurst is the maximum number of export requests allowed per interval.
	// GitLab project import/export API limit: 6 requests per minute per user.
	ExportRateLimitBurst = 6

	// ImportRateLimitIntervalSeconds is the time window for import rate limiting (60 seconds = 1 minute).
	ImportRateLimitIntervalSeconds = 60

	// ImportRateLimitBurst is the maximum number of import requests allowed per interval.
	// GitLab project import/export API limit: 6 requests per minute per user.
	ImportRateLimitBurst = 6
)

GitLab API Rate Limits

These limits are based on GitLab's documented API rate limits per user: - Repository Files API: 5 requests/minute (for downloads) - Project Import/Export API: 6 requests/minute (for exports and imports)

⚠️ WARNING: DO NOT increase these values above GitLab's documented limits. Exceeding limits results in HTTP 429 errors and potential account restrictions.

References:

View Source
const (
	// ExportCheckIntervalSeconds is the delay between export status checks when polling GitLab.
	// Lower values provide more responsive feedback but increase API load.
	// Default: 5 seconds (balanced responsiveness/load).
	ExportCheckIntervalSeconds = 5

	// MaxExportRetries is the maximum number of consecutive "none" status responses
	// before giving up on export. Prevents infinite loops for stale exports.
	// Default: 5 retries = 25 seconds of "none" responses before timeout.
	MaxExportRetries = 5

	// DefaultExportTimeoutMins is the default timeout for export operations in minutes.
	// Large projects may take longer. This can be overridden via configuration.
	// Default: 10 minutes.
	DefaultExportTimeoutMins = 10
)

Export Operation Constants

These control the behavior of project export polling and retry logic.

View Source
const (
	// ImportTimeoutMinutes is the maximum time to wait for an import operation to complete.
	// Large projects (>1GB) may need longer timeouts.
	// Default: 10 minutes (matches export timeout for symmetry).
	ImportTimeoutMinutes = 10

	// ImportPollSeconds is the interval between import status checks when polling GitLab.
	// Lower values provide more responsive feedback but increase API load.
	// Default: 5 seconds (matches export polling interval).
	ImportPollSeconds = 5
)

Import Operation Constants

These control the behavior of project import polling logic.

View Source
const (
	// BytesPerKB is the number of bytes in one kilobyte (1,024).
	// Use storage.KB instead for new code.
	//
	// Deprecated: Use constants.KB from storage.go.
	BytesPerKB = 1024

	// BytesPerMB is the number of bytes in one megabyte (1,048,576).
	// Use storage.MB instead for new code.
	//
	// Deprecated: Use constants.MB from storage.go.
	BytesPerMB = BytesPerKB * BytesPerKB
)

File Size Display

These constants are used for converting byte counts to human-readable formats.

View Source
const (
	// Byte is the base unit (included for completeness).
	Byte = 1

	// KB is one kilobyte (1,024 bytes).
	KB = 1024

	// MB is one megabyte (1,024 kilobytes = 1,048,576 bytes).
	MB = 1024 * KB

	// GB is one gigabyte (1,024 megabytes = 1,073,741,824 bytes).
	GB = 1024 * MB

	// TB is one terabyte (1,024 gigabytes).
	TB = 1024 * GB
)

Size Constants

Standard binary size units (powers of 1024, not 1000).

View Source
const (
	// CopyBufferSize is the buffer size for local file copy operations.
	// 32KB provides good balance between memory usage and I/O performance.
	CopyBufferSize = 32 * KB

	// DefaultBufferSize is the default buffer size for generic I/O operations.
	DefaultBufferSize = 32 * KB
)

Buffer Sizes

These control memory allocation for file operations. Larger buffers improve throughput but use more memory.

View Source
const (
	// DefaultFilePermission is the default permission mode for created files (rw-r--r--).
	// Owner can read/write, group/others can read.
	DefaultFilePermission = 0644

	// DefaultDirPermission is the default permission mode for created directories (rwxr-xr-x).
	// Owner can read/write/execute, group/others can read/execute.
	DefaultDirPermission = 0755
)

File Permissions

Standard Unix file permission constants.

View Source
const (
	// MaxExportTimeoutMinutes is the maximum allowed export timeout in minutes.
	// Prevents unreasonably long timeouts (e.g., typos in config).
	// Maximum: 24 hours = 1440 minutes.
	MaxExportTimeoutMinutes = 1440

	// DefaultTimeoutSeconds is the default timeout for HTTP operations in seconds.
	// Default: 1 hour = 3600 seconds.
	DefaultTimeoutSeconds = 3600
)

Configuration Timeouts and Limits.

View Source
const (
	// S3BucketNameMinLength is the minimum allowed S3 bucket name length.
	S3BucketNameMinLength = 3

	// S3BucketNameMaxLength is the maximum allowed S3 bucket name length.
	S3BucketNameMaxLength = 63

	// S3RegionMinLength is the minimum allowed AWS region string length.
	// Shortest region is "us-east-1" (9 chars), but allow 2 for validation flexibility.
	S3RegionMinLength = 2

	// S3RegionMaxLength is the maximum allowed AWS region string length.
	// Longest region is ~20 characters (e.g., "ap-southeast-3").
	S3RegionMaxLength = 20
)

AWS S3 Validation Constants

These limits are defined by AWS S3 bucket naming rules. Reference: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html

View Source
const (
	// RedactedValue is the placeholder for redacted credentials in logs/output.
	RedactedValue = "***REDACTED***"
)

Configuration Redaction.

View Source
const (
	// S3PathMinParts is the minimum number of path components for S3 paths.
	// Format: bucket/key → 2 parts.
	S3PathMinParts = 2
)

S3 Path Parsing.

View Source
const (
	// SeparatorWidth is the character width of console separators/dividers.
	// Used for visual section breaks in restore results and status output.
	SeparatorWidth = 60
)

CLI Output Formatting

These constants control the visual formatting of CLI output.

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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