unfinished main.go

This commit is contained in:
Adora Laura Kalb 2024-07-24 17:36:44 +02:00
parent 710b99d02d
commit 70460873ac
Signed by: adoralaura
SSH key fingerprint: SHA256:3XrkbR8ikAZJVtYfaUliX1MhmJYVAe/ocIb/MiDHBJ8

View file

@ -0,0 +1,64 @@
/*
Copyright © 2024 Laura Kalb <dev@lauka.net>
The code of this project is available under the MIT license. See the LICENSE file for more info.
*/
package main
import (
"fmt"
"log"
"log/slog"
"os"
"code.lila.network/adoralaura/mailcow-admin-aliases/internal/configuration"
"code.lila.network/adoralaura/mailcow-admin-aliases/internal/logging"
"code.lila.network/adoralaura/mailcow-admin-aliases/internal/mailcow"
"github.com/spf13/pflag"
)
func main() {
quiet := pflag.BoolP("quiet", "q", false, "Disable logging")
verbose := pflag.Bool("debug", false, "Enable debug logging (beats --quiet)")
pflag.BoolVarP(&configuration.DryRun, "dry-run", "d", false, "Show what this application *would* do")
pflag.StringVarP(&configuration.ConfigFile, "config", "c", "", "Path to config file (default: $WorkDir/config.yaml)")
pflag.Parse()
logging.NewSlogLogger(*quiet, *verbose)
var cfg configuration.Config
err := cfg.LoadFromDisk()
if err != nil {
log.Fatalf("failed to load config: %v", err.Error())
}
var wantedAliases []string
domains, err := mailcow.LoadDomains(cfg)
if err != nil {
slog.Error("failed to get domains", "error", err.Error())
os.Exit(1)
}
for _, domain := range domains {
for _, prefix := range cfg.MailPrefixes {
address := prefix + "@" + domain.DomainName
if address != cfg.AdminEmail {
wantedAliases = append(wantedAliases, address)
}
}
}
aliases, err := mailcow.LoadAliases(cfg)
if err != nil {
slog.Error("failed to get aliases", "error", err.Error())
os.Exit(1)
}
slog.Info(fmt.Sprintf("Found %v domains, %v aliases.", len(domains), len(aliases)))
for _, alias := range aliases {
for _, wantedPrefix := range cfg.MailPrefixes {
}
}
}