aboutsummaryrefslogtreecommitdiff
path: root/internal/conf
diff options
context:
space:
mode:
Diffstat (limited to 'internal/conf')
-rw-r--r--internal/conf/mocks.go32
-rw-r--r--internal/conf/static.go173
2 files changed, 124 insertions, 81 deletions
diff --git a/internal/conf/mocks.go b/internal/conf/mocks.go
index 1f8e16f2..d4e57d38 100644
--- a/internal/conf/mocks.go
+++ b/internal/conf/mocks.go
@@ -8,6 +8,14 @@ import (
"testing"
)
+func SetMockApp(t *testing.T, opts AppOpts) {
+ before := App
+ App = opts
+ t.Cleanup(func() {
+ App = before
+ })
+}
+
func SetMockServer(t *testing.T, opts ServerOpts) {
before := Server
Server = opts
@@ -15,3 +23,27 @@ func SetMockServer(t *testing.T, opts ServerOpts) {
Server = before
})
}
+
+func SetMockSSH(t *testing.T, opts SSHOpts) {
+ before := SSH
+ SSH = opts
+ t.Cleanup(func() {
+ SSH = before
+ })
+}
+
+func SetMockRepository(t *testing.T, opts RepositoryOpts) {
+ before := Repository
+ Repository = opts
+ t.Cleanup(func() {
+ Repository = before
+ })
+}
+
+func SetMockUI(t *testing.T, opts UIOpts) {
+ before := UI
+ UI = opts
+ t.Cleanup(func() {
+ UI = before
+ })
+}
diff --git a/internal/conf/static.go b/internal/conf/static.go
index aa73a180..b0092dde 100644
--- a/internal/conf/static.go
+++ b/internal/conf/static.go
@@ -13,6 +13,9 @@ import (
)
// ℹ️ README: This file contains static values that should only be set at initialization time.
+//
+// ⚠️ WARNING: After changing any options, do not forget to update template of
+// "/admin/config" page as well.
// HasMinWinSvc is whether the application is built with Windows Service support.
//
@@ -30,67 +33,7 @@ var (
// CustomConf returns the absolute path of custom configuration file that is used.
var CustomConf string
-// ⚠️ WARNING: After changing the following section, do not forget to update template of
-// "/admin/config" page as well.
var (
- // Application settings
- App struct {
- // ⚠️ WARNING: Should only be set by the main package (i.e. "gogs.go").
- Version string `ini:"-"`
-
- BrandName string
- RunUser string
- RunMode string
- }
-
- // SSH settings
- SSH 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"`
- }
-
- // Repository settings
- Repository 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
-
- // 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"`
- }
-
// Security settings
Security struct {
InstallLock bool
@@ -295,27 +238,6 @@ var (
MaxResponseItems int
}
- // UI settings
- UI 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 struct {
- RepoPagingNum int
- NewsFeedPagingNum int
- CommitsPagingNum int
- } `ini:"ui.user"`
- }
-
// Prometheus settings
Prometheus struct {
Enabled bool
@@ -334,6 +256,18 @@ var (
HasRobotsTxt bool
)
+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
+}
+
+// Application settings
+var App AppOpts
+
type ServerOpts struct {
ExternalURL string `ini:"EXTERNAL_URL"`
Domain string
@@ -365,6 +299,58 @@ type ServerOpts struct {
// Server settings
var Server ServerOpts
+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"`
+}
+
+// SSH settings
+var SSH SSHOpts
+
+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
+
+ // 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"`
+}
+
+// Repository settings
+var Repository RepositoryOpts
+
type DatabaseOpts struct {
Type string
Host string
@@ -389,6 +375,31 @@ type LFSOpts struct {
// LFS settings
var LFS LFSOpts
+type UIUserOpts struct {
+ RepoPagingNum int
+ NewsFeedPagingNum int
+ CommitsPagingNum int
+}
+
+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"`
+}
+
+// UI settings
+var UI UIOpts
+
type i18nConf struct {
Langs []string `delim:","`
Names []string `delim:","`