aboutsummaryrefslogtreecommitdiffhomepage
path: root/config/config.go
blob: 2eaa31ce6d4e60d61eebdde4461534133056d435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package config

import (
	"os"
	"strconv"
)

// Default config parameters values
const (
	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"
)

// Config manages configuration parameters.
type Config struct{}

// Get returns a config parameter value.
func (c *Config) Get(key, fallback string) string {
	value := os.Getenv(key)
	if value == "" {
		return fallback
	}

	return value
}

// GetInt returns a config parameter as integer.
func (c *Config) GetInt(key string, fallback int) int {
	value := os.Getenv(key)
	if value == "" {
		return fallback
	}

	v, _ := strconv.Atoi(value)
	return v
}

// NewConfig returns a new Config.
func NewConfig() *Config {
	return &Config{}
}