63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
/* diodemail - send-only smtp server
|
|
* Copyright (c) 2024 Gnarwhal
|
|
*
|
|
* This file is part of diodemail.
|
|
*
|
|
* diodemail is free software: you can redistribute it and/or modify it under the terms of
|
|
* the GNU General Public License as published by the Free Software Foundation,
|
|
* either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* diodemail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* diodemail. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"encoding/json"
|
|
)
|
|
|
|
type Config struct {
|
|
LogLevel string
|
|
Host string
|
|
Ports PortConfig
|
|
Certificate CertConfig
|
|
Auth AuthConfig
|
|
}
|
|
|
|
type PortConfig struct {
|
|
Plain string
|
|
TLS string
|
|
}
|
|
|
|
type CertConfig struct {
|
|
CertFile string
|
|
KeyFile string
|
|
}
|
|
|
|
type AuthConfig struct {
|
|
Enabled bool
|
|
PasswordHash string
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
contents, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var config Config
|
|
config.Ports.Plain = "disabled"
|
|
config.Ports.TLS = "disabled"
|
|
config.Auth.Enabled = true
|
|
err = json.Unmarshal(contents, &config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &config, nil
|
|
}
|