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

package main

import (
	"io/ioutil"

	"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 []byte `yaml:"authToken"`
	Endpoint  string `yaml:"endpoint"`
}

func loadConfig(filename string) (*Config, error) {
	b, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	cfg := &Config{}
	err = yaml.Unmarshal(b, cfg)
	if err != nil {
		return nil, err
	}
	return cfg, nil
}