This part involves setting up a local SQLite database to store the DNS records that the Go app will serve. Here’s what you need to do:
- Linux/macOS: You can install SQLite via your package manager:
sudo apt-get install sqlite3 # Ubuntu/Debian
sudo pacman -S sqlite # Arch Linux
brew install sqlite # macOS
- Windows: Download the SQLite tools from the official website: https://sqlite.org/download.html
Create a new SQLite database file (if it doesn't exist yet). Open your terminal or command prompt and run:
sqlite3 dns_records.db
This command starts the SQLite shell with the database file dns_records.db. If the file doesn’t exist, it will be created in the current directory.
Inside the SQLite shell (you'll see a prompt like sqlite>), run the following SQL command to create a table for DNS records:
CREATE TABLE records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
type TEXT NOT NULL,
value TEXT NOT NULL
);
- id: A unique identifier for each record (auto-incremented).
- name: The domain name (e.g., example.com).
- type: The DNS record type (e.g., A, MX, TXT).
- value: The corresponding value for the record (e.g., IP address for A record).
While still inside the SQLite shell, insert some example DNS records for testing:
INSERT INTO records (name, type, value) VALUES ('example.com', 'A', '93.184.216.34');
INSERT INTO records (name, type, value) VALUES ('example.com', 'MX', 'mail.example.com');
INSERT INTO records (name, type, value) VALUES ('example.com', 'TXT', 'v=spf1 include:example.com ~all');
- A Record: Maps the domain example.com to the IP 93.184.216.34.
- MX Record: Specifies the mail exchange server mail.example.com.
- TXT Record: Provides a sample SPF entry for the domain.
To confirm the records were added, run the following query:
SELECT * FROM records;
You should see output like this:
1|example.com|A|93.184.216.34
2|example.com|MX|mail.example.com
3|example.com|TXT|v=spf1 include:example.com ~all
Once you’re done inserting records, type:
.exit
This will exit the SQLite shell and save the changes to the dns_records.db file.