Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use go generate for TLD generation #5

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0: QmaeHSCBd9XjXxmgHEiKkHtLcMCb2eZsPLKT7bHgBfBkqw
2 changes: 2 additions & 0 deletions is_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package isdomain

import "strings"

//go:generate bash regenerate-tlds.sh

// IsICANNTLD returns whether the given string is a TLD (Top Level Domain),
// according to ICANN. Well, really according to the TLDs listed in this
// package.
Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"author": "jbenet",
"bugs": {
"URL": "https://github.com/jbenet/go-is-domain/issues"
},
"gx": {
"dvcsimport": "github.com/jbenet/go-is-domain"
},
"gxVersion": "0.7.0",
"language": "go",
"license": "MIT",
"name": "go-is-domain",
"version": "1.0.0"
}
26 changes: 26 additions & 0 deletions regenerate-tlds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

out=${1-tlds_iana.go}

list=$(mktemp)

wget https://data.iana.org/TLD/tlds-alpha-by-domain.txt -O $list

header=$(head -1 $list)

cat > $out <<EOF
package isdomain

// $header
var TLDs = map[string]bool{
EOF

grep -v '^#' $list | while read tld; do
echo -e "\t\"$tld\": true,"
done >> $out

echo '}' >> $out

gofmt -w $out


Loading