#!/bin/sh # records=`curl -sf http://www.iana.org/assignments/dns-parameters/dns-parameters-4.csv | cut -f1 -d',' | sort | uniq | awk '/^[A-Z][A-Z]*$/ { print $0 }'` || exit 1 echo "// AUTOGENERATED helper methods for IANA-registered RRTYPES. Do not edit." echo "// See generate_dsl_helpers.sh for details" echo "package dsl" echo " import ( \"fmt\" \"regexp\" ) " # A list of RRTypes might come in handy, you never know echo "var RRTypes = []string{" for record in $records; do echo " \"${record}\"," done echo "}" for record in $records; do echo " // Helper function to register a callback for ${record} queries. // The matcher is given as a string, which is compiled to a regular expression // (using regexp.MustCompile) with the following rules: // // * The regexp is anchored to the start of the match string(\"^\" at start) // * The case-insensitivity option is added \"(?i)\" // * The regexp is anchored to the end of the match string (\"$\" at end) // // If any of these options are unwelcome, you can use the DSL.Register and pass // a regexp and the \"${record}\" string directly. func (d *DSL) ${record}(matcher string, f Callback) { re := regexp.MustCompile(fmt.Sprintf(\"^(?i)%s$\", matcher)) d.Register(\"${record}\", re, f) }" done