From 3f5d108177c79c6a6a2b84de45409e1d6ee13cb9 Mon Sep 17 00:00:00 2001 From: Balakrishnan Balasubramanian Date: Thu, 21 Sep 2023 17:07:58 -0400 Subject: [PATCH] add MX record --- README.md | 3 ++- main.go | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 885b0ac..2ff446a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ CLI tool to manage cloudflare DNS records ## Features -1. Add/Modify `A`, `AAAA`, `CNAME` records +1. Add/Modify `A`, `AAAA`, `CNAME`, `MX` records 2. List/Delete records 3. Save all records in JSON format @@ -30,6 +30,7 @@ Usage of cloudflare-dns-cli: Domain name, e.g. example.com. env var: DOMAIN -i value IP address (default 127.0.0.1) + -m Set mx record with cname value -o string Path to save all records as json, e.g. ./records.json -s string diff --git a/main.go b/main.go index 1a95741..061a6ae 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ var ( sub = "" path string del = false + mx = false ) func genRecord() (libdns.Record, error) { @@ -30,11 +31,19 @@ func genRecord() (libdns.Record, error) { ipv6 := ip.To16() switch { case cname != "": - return libdns.Record{ - Type: "CNAME", - Name: sub, - Value: cname, - }, nil + if mx { + return libdns.Record{ + Type: "MX", + Name: sub, + Value: cname, + }, nil + } else { + return libdns.Record{ + Type: "CNAME", + Name: sub, + Value: cname, + }, nil + } case ipv4 != nil: return libdns.Record{ Type: "A", @@ -101,6 +110,7 @@ func main() { flag.StringVar(&cname, "c", cname, "CNAME target") flag.StringVar(&path, "o", path, "Path to save all records as json, e.g. ./records.json") flag.BoolVar(&del, "x", del, "Delete records of subdomain") + flag.BoolVar(&mx, "m", mx, "Set mx record with cname value") flag.Parse() provider := cloudflare.Provider{APIToken: token}