-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
80 lines (66 loc) · 2.83 KB
/
config.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/kelseyhightower/envconfig"
)
var (
pgSlotCreate bool
pgSlotReCreate bool
reindex bool
)
func init() {
flag.BoolVar(&pgSlotCreate, "create", false, "Create new replication slot, if specified slot does not exists.")
flag.BoolVar(&pgSlotReCreate, "recreate", false, "Deletes slot and creates new one.")
flag.BoolVar(&reindex, "reindex", false, "Start with a backup to populate data into empty ES cluster (not implemented)")
}
// Config for the application.
type Config struct {
Postgres struct {
// Postgres replication slot. Used to control WAL positions.
Slot string `envconfig:"PG_SLOT" default:"pg2es"`
// PostgresPublication containing databases and tables that should be replicated or indexed by the search engine.
Publication string `envconfig:"PG_PUBLICATION" default:"search"`
// PostgreSQL connection string
// Host string `encvonfig:"PGHOST" required:"true"`
Host string `envconfig:"PGHOST"`
// Port is the port of the Postgres server.
Port uint16 `envconfig:"PGPORT"`
// Database to connect to.
Database string `envconfig:"PGDATABASE"`
// User to use to connect to the database.
User string `envconfig:"PGUSER"`
// Password for the user.
Password string `envconfig:"PGPASSWORD"`
// Further PG environment variables listed in
// https://www.postgresql.org/docs/current/libpq-envars.html
// are also accepted, but not listed here.
}
Search struct {
// URL or host of ElasticSearch/OpenSearch. username and password can be defined here
URL string `envconfig:"SEARCH_HOST" required:"true"`
User string `envconfig:"SEARCH_USERNAME" required:"false"`
Password string `envconfig:"SEARCH_PASSWORD" required:"false"`
// BulkSizeLimit in Megabytes, limits request body size of bulk requests. Small values (2-8MB) are recommended. Extremely large requests do not improve performance, while causing extra memory pressure. Default elasticsearch limit is 100MB
BulkSizeLimit int `envconfig:"SEARCH_BULK_SIZE" default:"4"`
// PushInterval between bulk requests to the search engine.
PushInterval time.Duration `envconfig:"SEARCH_PUSH_INTERVAL" default:"30s"`
PushThrottle time.Duration `envconfig:"SEARCH_PUSH_THROTTLE" default:"500ms"`
PushDebounce time.Duration `envconfig:"SEARCH_PUSH_DEBOUNCE" default:"500ms"`
}
// LogFormat [ json (default) | cli ]
LogFormat string `envconfig:"LOG_FORMAT" default:"json"`
LogLevel string `envconfig:"LOG_LEVEL" default:"warn"`
// Internal http API and metrics. Default 0.0.0.0:80
Address string `envconfig:"ADDR"`
}
// FromEnv loads the configuration from environment variables. Panics if can not config us invalid
func FromEnv() *Config {
var cfg Config
if err := envconfig.Process("", &cfg); err != nil {
log.Fatal(fmt.Errorf("can not read initial config: %w", err))
}
return &cfg
}