Set all default config values in config package
This commit is contained in:
parent
6690f6a70e
commit
9ff3c4504c
10 changed files with 34 additions and 15 deletions
|
@ -9,13 +9,21 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Default config parameters values
|
||||||
const (
|
const (
|
||||||
DefaultBaseURL = "http://localhost"
|
DefaultBaseURL = "http://localhost"
|
||||||
|
DefaultDatabaseURL = "postgres://postgres:postgres@localhost/miniflux2?sslmode=disable"
|
||||||
|
DefaultWorkerPoolSize = 5
|
||||||
|
DefaultPollingFrequency = 60
|
||||||
|
DefaultBatchSize = 10
|
||||||
|
DefaultDatabaseMaxConns = 20
|
||||||
|
DefaultListenAddr = "127.0.0.1:8080"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
// Config manages configuration parameters.
|
||||||
}
|
type Config struct{}
|
||||||
|
|
||||||
|
// Get returns a config parameter value.
|
||||||
func (c *Config) Get(key, fallback string) string {
|
func (c *Config) Get(key, fallback string) string {
|
||||||
value := os.Getenv(key)
|
value := os.Getenv(key)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
|
@ -25,6 +33,7 @@ func (c *Config) Get(key, fallback string) string {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetInt returns a config parameter as integer.
|
||||||
func (c *Config) GetInt(key string, fallback int) int {
|
func (c *Config) GetInt(key string, fallback int) int {
|
||||||
value := os.Getenv(key)
|
value := os.Getenv(key)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
|
@ -35,6 +44,7 @@ func (c *Config) GetInt(key string, fallback int) int {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewConfig returns a new Config.
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
return &Config{}
|
return &Config{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.645632989 -0800 PST m=+0.024631837
|
// 2017-11-21 20:18:16.06757584 -0800 PST m=+0.047008676
|
||||||
|
|
||||||
package locale
|
package locale
|
||||||
|
|
||||||
|
|
17
main.go
17
main.go
|
@ -47,8 +47,17 @@ func run(cfg *config.Config, store *storage.Storage) {
|
||||||
server := server.NewServer(cfg, store, feedHandler)
|
server := server.NewServer(cfg, store, feedHandler)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
pool := scheduler.NewWorkerPool(feedHandler, cfg.GetInt("WORKER_POOL_SIZE", 5))
|
pool := scheduler.NewWorkerPool(
|
||||||
scheduler.NewScheduler(store, pool, cfg.GetInt("POLLING_FREQUENCY", 30), cfg.GetInt("BATCH_SIZE", 10))
|
feedHandler,
|
||||||
|
cfg.GetInt("WORKER_POOL_SIZE", config.DefaultWorkerPoolSize),
|
||||||
|
)
|
||||||
|
|
||||||
|
scheduler.NewScheduler(
|
||||||
|
store,
|
||||||
|
pool,
|
||||||
|
cfg.GetInt("POLLING_FREQUENCY", config.DefaultPollingFrequency),
|
||||||
|
cfg.GetInt("BATCH_SIZE", config.DefaultBatchSize),
|
||||||
|
)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
<-stop
|
<-stop
|
||||||
|
@ -82,8 +91,8 @@ func main() {
|
||||||
|
|
||||||
cfg := config.NewConfig()
|
cfg := config.NewConfig()
|
||||||
store := storage.NewStorage(
|
store := storage.NewStorage(
|
||||||
cfg.Get("DATABASE_URL", "postgres://postgres:postgres@localhost/miniflux2?sslmode=disable"),
|
cfg.Get("DATABASE_URL", config.DefaultDatabaseURL),
|
||||||
cfg.GetInt("DATABASE_MAX_CONNS", 20),
|
cfg.GetInt("DATABASE_MAX_CONNS", config.DefaultDatabaseMaxConns),
|
||||||
)
|
)
|
||||||
|
|
||||||
if *flagInfo {
|
if *flagInfo {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func NewServer(cfg *config.Config, store *storage.Storage, feedHandler *feed.Han
|
||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 10 * time.Second,
|
WriteTimeout: 10 * time.Second,
|
||||||
IdleTimeout: 60 * time.Second,
|
IdleTimeout: 60 * time.Second,
|
||||||
Addr: cfg.Get("LISTEN_ADDR", "127.0.0.1:8080"),
|
Addr: cfg.Get("LISTEN_ADDR", config.DefaultListenAddr),
|
||||||
Handler: getRoutes(cfg, store, feedHandler),
|
Handler: getRoutes(cfg, store, feedHandler),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.626742594 -0800 PST m=+0.005741442
|
// 2017-11-21 20:18:16.027243814 -0800 PST m=+0.006676650
|
||||||
|
|
||||||
package static
|
package static
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.629675274 -0800 PST m=+0.008674122
|
// 2017-11-21 20:18:16.030648994 -0800 PST m=+0.010081830
|
||||||
|
|
||||||
package static
|
package static
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.631783539 -0800 PST m=+0.010782387
|
// 2017-11-21 20:18:16.035467739 -0800 PST m=+0.014900575
|
||||||
|
|
||||||
package static
|
package static
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.643994492 -0800 PST m=+0.022993340
|
// 2017-11-21 20:18:16.064392532 -0800 PST m=+0.043825368
|
||||||
|
|
||||||
package template
|
package template
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.633723314 -0800 PST m=+0.012722162
|
// 2017-11-21 20:18:16.038376976 -0800 PST m=+0.017809812
|
||||||
|
|
||||||
package template
|
package template
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// 2017-11-21 19:31:59.625242989 -0800 PST m=+0.004241837
|
// 2017-11-21 20:18:16.024887819 -0800 PST m=+0.004320655
|
||||||
|
|
||||||
package sql
|
package sql
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue