Documentation ¶
Index ¶
- Constants
- Variables
- func AppPath() string
- func CheckRunUser(runUser string) (string, bool)
- func CustomDir() string
- func HomeDir() string
- func Init(customConf string) error
- func InitLogging(hookMode bool)
- func IsProdMode() bool
- func IsWindowsRuntime() bool
- func MustInit(customConf string)
- func SetMockApp(t *testing.T, opts AppOpts)
- func SetMockAuth(t *testing.T, otps AuthOpts)
- func SetMockPicture(t *testing.T, opts PictureOpts)
- func SetMockRepository(t *testing.T, opts RepositoryOpts)
- func SetMockSSH(t *testing.T, opts SSHOpts)
- func SetMockServer(t *testing.T, opts ServerOpts)
- func SetMockUI(t *testing.T, opts UIOpts)
- func UserDefaultAvatarURLPath() string
- func WorkDir() string
- type AppOpts
- type AuthOpts
- type DatabaseOpts
- type LFSOpts
- type PictureOpts
- type RepositoryOpts
- type SSHOpts
- type ServerOpts
- type UIOpts
- type UIUserOpts
Constants ¶
const UsersAvatarPathPrefix = "avatars"
UsersAvatarPathPrefix is the path prefix to user avatars.
Variables ¶
var ( BuildTime string BuildCommit string )
Build time and commit information.
⚠️ WARNING: should only be set by "-ldflags".
var ( // Security settings Security struct { InstallLock bool SecretKey string LoginRememberDays int CookieRememberName string CookieUsername string CookieSecure bool EnableLoginStatusCookie bool LoginStatusCookieName string LocalNetworkAllowlist []string `delim:","` } // Email settings Email struct { Enabled bool SubjectPrefix string Host string From string User string Password string DisableHELO bool `ini:"DISABLE_HELO"` HELOHostname string `ini:"HELO_HOSTNAME"` SkipVerify bool UseCertificate bool CertFile string KeyFile string UsePlainText bool AddPlainTextAlt bool // Derived from other static values FromEmail string `ini:"-"` // Parsed email address of From without person's name. } // User settings User struct { EnableEmailNotification bool } // Session settings Session struct { Provider string ProviderConfig string CookieName string CookieSecure bool GCInterval int64 `ini:"GC_INTERVAL"` MaxLifeTime int64 CSRFCookieName string `ini:"CSRF_COOKIE_NAME"` } // Cache settings Cache struct { Adapter string Interval int Host string } // HTTP settings HTTP struct { AccessControlAllowOrigin string } // Attachment settings Attachment struct { Enabled bool Path string AllowedTypes []string `delim:"|"` MaxSize int64 MaxFiles int } // Release settings Release struct { Attachment struct { Enabled bool AllowedTypes []string `delim:"|"` MaxSize int64 MaxFiles int } `ini:"release.attachment"` } // Time settings Time struct { Format string // Derived from other static values FormatLayout string `ini:"-"` // Actual layout of the Format. } // Mirror settings Mirror struct { DefaultInterval int } // Webhook settings Webhook struct { Types []string DeliverTimeout int SkipTLSVerify bool `ini:"SKIP_TLS_VERIFY"` PagingNum int } // Markdown settings Markdown struct { EnableHardLineBreak bool CustomURLSchemes []string `ini:"CUSTOM_URL_SCHEMES"` FileExtensions []string } // Smartypants settings Smartypants struct { Enabled bool Fractions bool Dashes bool LatexDashes bool AngledQuotes bool } // Admin settings Admin struct { DisableRegularOrgCreation bool } // Cron tasks Cron struct { UpdateMirror struct { Enabled bool RunAtStart bool Schedule string } `ini:"cron.update_mirrors"` RepoHealthCheck struct { Enabled bool RunAtStart bool Schedule string Timeout time.Duration Args []string `delim:" "` } `ini:"cron.repo_health_check"` CheckRepoStats struct { Enabled bool RunAtStart bool Schedule string } `ini:"cron.check_repo_stats"` RepoArchiveCleanup struct { Enabled bool RunAtStart bool Schedule string OlderThan time.Duration } `ini:"cron.repo_archive_cleanup"` } // Git settings Git struct { // ⚠️ WARNING: Should only be set by "internal/db/repo.go". Version string `ini:"-"` DisableDiffHighlight bool MaxDiffFiles int `ini:"MAX_GIT_DIFF_FILES"` MaxDiffLines int `ini:"MAX_GIT_DIFF_LINES"` MaxDiffLineChars int `ini:"MAX_GIT_DIFF_LINE_CHARACTERS"` GCArgs []string `ini:"GC_ARGS" delim:" "` Timeout struct { Migrate int Mirror int Clone int Pull int Diff int GC int `ini:"GC"` } `ini:"git.timeout"` } // API settings API struct { MaxResponseItems int } // Prometheus settings Prometheus struct { Enabled bool EnableBasicAuth bool BasicAuthUsername string BasicAuthPassword string } // Other settings Other struct { ShowFooterBranding bool ShowFooterTemplateLoadTime bool } // Global setting HasRobotsTxt bool )
var ( UseSQLite3 bool UseMySQL bool UsePostgreSQL bool UseMSSQL bool )
Indicates which database backend is currently being used.
var CustomConf string
CustomConf returns the absolute path of custom configuration file that is used.
var File *ini.File
File is the configuration object.
var HasMinWinSvc bool
HasMinWinSvc is whether the application is built with Windows Service support.
⚠️ WARNING: should only be set by "internal/conf/static_minwinsvc.go".
var HookMode bool
HookMode indicates whether program starts as Git server-side hook callback. All operations should be done synchronously to prevent program exits before finishing.
⚠️ WARNING: Should only be set by "internal/cmd/serv.go".
var I18n *i18nConf
I18n settings
var Log *logConf
Log settings
Functions ¶
func CheckRunUser ¶
CheckRunUser returns false if configured run user does not match actual user that runs the app. The first return value is the actual user name. This check is ignored under Windows since SSH remote login is not the main method to login on Windows.
func CustomDir ¶
func CustomDir() string
CustomDir returns the absolute path of the custom directory that contains local overrides. It reads the value of environment variable GOGS_CUSTOM. When not set, it uses the work directory returned by WorkDir function.
func HomeDir ¶
func HomeDir() string
HomeDir returns the home directory by reading environment variables. It may return empty string when environment variables are not set.
func Init ¶
Init initializes configuration from conf assets and given custom configuration file. If `customConf` is empty, it falls back to default location, i.e. "<WORK DIR>/custom". It is safe to call this function multiple times with desired `customConf`, but it is not concurrent safe.
NOTE: The order of loading configuration sections matters as one may depend on another.
⚠️ WARNING: Do not print anything in this function other than warnings.
func InitLogging ¶
func InitLogging(hookMode bool)
InitLogging initializes the logging service of the application. When the "hookMode" is true, it only initializes the root path for log files without creating any logger. It will also not remove the primary logger in "hookMode" and is up to the caller to decide when to remove it.
func IsProdMode ¶
func IsProdMode() bool
IsProdMode returns true if the application is running in production mode.
func IsWindowsRuntime ¶
func IsWindowsRuntime() bool
IsWindowsRuntime returns true if the current runtime in Windows.
func MustInit ¶
func MustInit(customConf string)
MustInit panics if configuration initialization failed.
func SetMockApp ¶ added in v0.13.0
func SetMockAuth ¶ added in v0.13.0
func SetMockPicture ¶ added in v0.13.0
func SetMockPicture(t *testing.T, opts PictureOpts)
func SetMockRepository ¶ added in v0.13.0
func SetMockRepository(t *testing.T, opts RepositoryOpts)
func SetMockSSH ¶ added in v0.13.0
func SetMockServer ¶
func SetMockServer(t *testing.T, opts ServerOpts)
func UserDefaultAvatarURLPath ¶ added in v0.13.0
func UserDefaultAvatarURLPath() string
UserDefaultAvatarURLPath returns the URL path of the default user avatar.
Types ¶
type AppOpts ¶ added in v0.13.0
type AppOpts struct { // ⚠️ WARNING: Should only be set by the main package (i.e. "gogs.go"). Version string `ini:"-"` BrandName string RunUser string RunMode string }
var App AppOpts
Application settings
type AuthOpts ¶ added in v0.13.0
type AuthOpts struct { ActivateCodeLives int ResetPasswordCodeLives int RequireEmailConfirmation bool RequireSigninView bool DisableRegistration bool EnableRegistrationCaptcha bool EnableReverseProxyAuthentication bool EnableReverseProxyAutoRegistration bool ReverseProxyAuthenticationHeader string }
var Auth AuthOpts
Authentication settings
type DatabaseOpts ¶
type DatabaseOpts struct { Type string Host string Name string Schema string User string Password string SSLMode string `ini:"SSL_MODE"` Path string MaxOpenConns int MaxIdleConns int }
var Database DatabaseOpts
Database settings
type PictureOpts ¶ added in v0.13.0
type PictureOpts struct { AvatarUploadPath string RepositoryAvatarUploadPath string GravatarSource string DisableGravatar bool EnableFederatedAvatar bool // Derived from other static values LibravatarService *libravatar.Libravatar `ini:"-"` // Initialized client for federated avatar. }
var Picture PictureOpts
Picture settings
type RepositoryOpts ¶ added in v0.13.0
type RepositoryOpts struct { Root string ScriptType string ANSICharset string `ini:"ANSI_CHARSET"` ForcePrivate bool MaxCreationLimit int PreferredLicenses []string DisableHTTPGit bool `ini:"DISABLE_HTTP_GIT"` EnableLocalPathMigration bool EnableRawFileRenderMode bool CommitsFetchConcurrency int DefaultBranch string // Repository editor settings Editor struct { LineWrapExtensions []string PreviewableFileModes []string } `ini:"repository.editor"` // Repository upload settings Upload struct { Enabled bool TempPath string AllowedTypes []string `delim:"|"` FileMaxSize int64 MaxFiles int } `ini:"repository.upload"` }
var Repository RepositoryOpts
Repository settings
type SSHOpts ¶ added in v0.13.0
type SSHOpts struct { Disabled bool `ini:"DISABLE_SSH"` Domain string `ini:"SSH_DOMAIN"` Port int `ini:"SSH_PORT"` RootPath string `ini:"SSH_ROOT_PATH"` KeygenPath string `ini:"SSH_KEYGEN_PATH"` KeyTestPath string `ini:"SSH_KEY_TEST_PATH"` MinimumKeySizeCheck bool MinimumKeySizes map[string]int `ini:"-"` // Load from [ssh.minimum_key_sizes] RewriteAuthorizedKeysAtStart bool StartBuiltinServer bool `ini:"START_SSH_SERVER"` ListenHost string `ini:"SSH_LISTEN_HOST"` ListenPort int `ini:"SSH_LISTEN_PORT"` ServerCiphers []string `ini:"SSH_SERVER_CIPHERS"` ServerMACs []string `ini:"SSH_SERVER_MACS"` ServerAlgorithms []string `ini:"SSH_SERVER_ALGORITHMS"` }
var SSH SSHOpts
SSH settings
type ServerOpts ¶
type ServerOpts struct { ExternalURL string `ini:"EXTERNAL_URL"` Domain string Protocol string HTTPAddr string `ini:"HTTP_ADDR"` HTTPPort string `ini:"HTTP_PORT"` CertFile string KeyFile string TLSMinVersion string `ini:"TLS_MIN_VERSION"` UnixSocketPermission string LocalRootURL string `ini:"LOCAL_ROOT_URL"` OfflineMode bool DisableRouterLog bool EnableGzip bool AppDataPath string LoadAssetsFromDisk bool LandingURL string `ini:"LANDING_URL"` // Derived from other static values URL *url.URL `ini:"-"` // Parsed URL object of ExternalURL. Subpath string `ini:"-"` // Subpath found the ExternalURL. Should be empty when not found. SubpathDepth int `ini:"-"` // The number of slashes found in the Subpath. UnixSocketMode os.FileMode `ini:"-"` // Parsed file mode of UnixSocketPermission. }
var Server ServerOpts
Server settings
type UIOpts ¶ added in v0.13.0
type UIOpts struct { ExplorePagingNum int IssuePagingNum int FeedMaxCommitNum int ThemeColorMetaTag string MaxDisplayFileSize int64 Admin struct { UserPagingNum int RepoPagingNum int NoticePagingNum int OrgPagingNum int } `ini:"ui.admin"` User UIUserOpts `ini:"ui.user"` }
var UI UIOpts
UI settings