aboutsummaryrefslogtreecommitdiff
path: root/config.go
blob: a0f17db6e55555eda1dca90494fed9cb48edb471 (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
// SPDX-FileCopyrightText: © 2020 Grégoire Duchêne <gduchene@awhk.org>
// SPDX-License-Identifier: ISC

package main

import (
	"io"

	"gopkg.in/yaml.v3"
)

type Config struct {
	Message Message `yaml:"message"`
	SMTP    SMTP    `yaml:"smtp"`
	Twilio  Twilio  `yaml:"twilio"`
}

type Message struct {
	From     string `yaml:"from"`
	To       string `yaml:"to"`
	Subject  string `yaml:"subject"`
	Template string `yaml:"template"`
}

type SMTP struct {
	Address  string `yaml:"hostname"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

type Twilio struct {
	Address   string `yaml:"address"`
	AuthToken string `yaml:"authToken"`
	Endpoint  string `yaml:"endpoint"`
}

func loadConfig(r io.Reader) (*Config, error) {
	cfg := &Config{}
	if err := yaml.NewDecoder(r).Decode(cfg); err != nil {
		return nil, err
	}
	return cfg, nil
}