options.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // Copyright 2019 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package config // import "miniflux.app/config"
  5. const (
  6. defaultBaseURL = "http://localhost"
  7. defaultWorkerPoolSize = 5
  8. defaultPollingFrequency = 60
  9. defaultBatchSize = 10
  10. defaultDatabaseURL = "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
  11. defaultDatabaseMaxConns = 20
  12. defaultDatabaseMinConns = 1
  13. defaultArchiveReadDays = 60
  14. defaultListenAddr = "127.0.0.1:8080"
  15. defaultCertFile = ""
  16. defaultKeyFile = ""
  17. defaultCertDomain = ""
  18. defaultCertCache = "/tmp/cert_cache"
  19. defaultCleanupFrequency = 24
  20. defaultProxyImages = "http-only"
  21. defaultOAuth2ClientID = ""
  22. defaultOAuth2ClientSecret = ""
  23. defaultOAuth2RedirectURL = ""
  24. defaultOAuth2Provider = ""
  25. )
  26. // Options contains configuration options.
  27. type Options struct {
  28. HTTPS bool
  29. hsts bool
  30. httpService bool
  31. schedulerService bool
  32. debug bool
  33. baseURL string
  34. rootURL string
  35. basePath string
  36. databaseURL string
  37. databaseMaxConns int
  38. databaseMinConns int
  39. runMigrations bool
  40. listenAddr string
  41. certFile string
  42. certDomain string
  43. certCache string
  44. certKeyFile string
  45. cleanupFrequency int
  46. archiveReadDays int
  47. pollingFrequency int
  48. batchSize int
  49. workerPoolSize int
  50. createAdmin bool
  51. proxyImages string
  52. oauth2UserCreationAllowed bool
  53. oauth2ClientID string
  54. oauth2ClientSecret string
  55. oauth2RedirectURL string
  56. oauth2Provider string
  57. pocketConsumerKey string
  58. }
  59. // HasDebugMode returns true if debug mode is enabled.
  60. func (o *Options) HasDebugMode() bool {
  61. return o.debug
  62. }
  63. // BaseURL returns the application base URL with path.
  64. func (o *Options) BaseURL() string {
  65. return o.baseURL
  66. }
  67. // RootURL returns the base URL without path.
  68. func (o *Options) RootURL() string {
  69. return o.rootURL
  70. }
  71. // BasePath returns the application base path according to the base URL.
  72. func (o *Options) BasePath() string {
  73. return o.basePath
  74. }
  75. // IsDefaultDatabaseURL returns true if the default database URL is used.
  76. func (o *Options) IsDefaultDatabaseURL() bool {
  77. return o.databaseURL == defaultDatabaseURL
  78. }
  79. // DatabaseURL returns the database URL.
  80. func (o *Options) DatabaseURL() string {
  81. return o.databaseURL
  82. }
  83. // DatabaseMaxConns returns the maximum number of database connections.
  84. func (o *Options) DatabaseMaxConns() int {
  85. return o.databaseMaxConns
  86. }
  87. // DatabaseMinConns returns the minimum number of database connections.
  88. func (o *Options) DatabaseMinConns() int {
  89. return o.databaseMinConns
  90. }
  91. // ListenAddr returns the listen address for the HTTP server.
  92. func (o *Options) ListenAddr() string {
  93. return o.listenAddr
  94. }
  95. // CertFile returns the SSL certificate filename if any.
  96. func (o *Options) CertFile() string {
  97. return o.certFile
  98. }
  99. // CertKeyFile returns the private key filename for custom SSL certificate.
  100. func (o *Options) CertKeyFile() string {
  101. return o.certKeyFile
  102. }
  103. // CertDomain returns the domain to use for Let's Encrypt certificate.
  104. func (o *Options) CertDomain() string {
  105. return o.certDomain
  106. }
  107. // CertCache returns the directory to use for Let's Encrypt session cache.
  108. func (o *Options) CertCache() string {
  109. return o.certCache
  110. }
  111. // CleanupFrequency returns the interval for cleanup jobs.
  112. func (o *Options) CleanupFrequency() int {
  113. return o.cleanupFrequency
  114. }
  115. // WorkerPoolSize returns the number of background worker.
  116. func (o *Options) WorkerPoolSize() int {
  117. return o.workerPoolSize
  118. }
  119. // PollingFrequency returns the interval to refresh feeds in the background.
  120. func (o *Options) PollingFrequency() int {
  121. return o.pollingFrequency
  122. }
  123. // BatchSize returns the number of feeds to send for background processing.
  124. func (o *Options) BatchSize() int {
  125. return o.batchSize
  126. }
  127. // IsOAuth2UserCreationAllowed returns true if user creation is allowed for OAuth2 users.
  128. func (o *Options) IsOAuth2UserCreationAllowed() bool {
  129. return o.oauth2UserCreationAllowed
  130. }
  131. // OAuth2ClientID returns the OAuth2 Client ID.
  132. func (o *Options) OAuth2ClientID() string {
  133. return o.oauth2ClientID
  134. }
  135. // OAuth2ClientSecret returns the OAuth2 client secret.
  136. func (o *Options) OAuth2ClientSecret() string {
  137. return o.oauth2ClientSecret
  138. }
  139. // OAuth2RedirectURL returns the OAuth2 redirect URL.
  140. func (o *Options) OAuth2RedirectURL() string {
  141. return o.oauth2RedirectURL
  142. }
  143. // OAuth2Provider returns the name of the OAuth2 provider configured.
  144. func (o *Options) OAuth2Provider() string {
  145. return o.oauth2Provider
  146. }
  147. // HasHSTS returns true if HTTP Strict Transport Security is enabled.
  148. func (o *Options) HasHSTS() bool {
  149. return o.hsts
  150. }
  151. // RunMigrations returns true if the environment variable RUN_MIGRATIONS is not empty.
  152. func (o *Options) RunMigrations() bool {
  153. return o.runMigrations
  154. }
  155. // CreateAdmin returns true if the environment variable CREATE_ADMIN is not empty.
  156. func (o *Options) CreateAdmin() bool {
  157. return o.createAdmin
  158. }
  159. // ProxyImages returns "none" to never proxy, "http-only" to proxy non-HTTPS, "all" to always proxy.
  160. func (o *Options) ProxyImages() string {
  161. return o.proxyImages
  162. }
  163. // HasHTTPService returns true if the HTTP service is enabled.
  164. func (o *Options) HasHTTPService() bool {
  165. return o.httpService
  166. }
  167. // HasSchedulerService returns true if the scheduler service is enabled.
  168. func (o *Options) HasSchedulerService() bool {
  169. return o.schedulerService
  170. }
  171. // ArchiveReadDays returns the number of days after which marking read items as removed.
  172. func (o *Options) ArchiveReadDays() int {
  173. return o.archiveReadDays
  174. }
  175. // PocketConsumerKey returns the Pocket Consumer Key if configured.
  176. func (o *Options) PocketConsumerKey(defaultValue string) string {
  177. if o.pocketConsumerKey != "" {
  178. return o.pocketConsumerKey
  179. }
  180. return defaultValue
  181. }