Browser Extension: fossjon.wp.com/2020/09/15/…browser-extensions/
I haven’t posted much GO related code on this blog before as I am more of a fan of C, Python, Java/JS, etc. I initially found its syntax to be a bit harder to read due to the variable typing being placed after the variable name. It can make it harder to track and understand if the variable you’re looking at is a: mutable or immutable, pointer or constant, array or singular, referenced or dereferenced, local or global, etc.
It does combine a lot of power that you would typically find in a more structured language (like Java) along with being flexibile and relaxed (like Python).
Anyway, I’ve been trying to learn its syntax and capabilities recently and I created a basic GO program which runs on a DNS server framework (github dependency). It reads in a regex based domain blocklist text file and it also forwards the rest of the queries on for regular resolution.
Source Code: https://github.com/stoops/dnsrb/blob/main/dnsrb.go
$ go run dnsrb.go Starting: 53053 Reading file ... A-Query: facebook.com. A-Reply: 127.0.0.1 A-Query: www.facebook.com. A-Reply: 127.0.0.1 A-Query: blah.facebook.com. A-Reply: 127.0.0.1 A-Query: fb.me. A-Reply: 127.0.0.1 A-Query: amazon.ca. A-Reply: 188.8.131.52 A-Reply: 184.108.40.206 A-Reply: 220.127.116.11 $ echo ; for d in facebook.com www.facebook.com blah.facebook.com fb.me amazon.ca ; do echo "[$d] -> $(dig @127.0.0.1 -p 53053 $d +short)" ; done ; echo [facebook.com] -> 127.0.0.1 [www.facebook.com] -> 127.0.0.1 [blah.facebook.com] -> 127.0.0.1 [fb.me] -> 127.0.0.1 [amazon.ca] -> 18.104.22.168 22.214.171.124 126.96.36.199