diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d2f19d2 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,488 @@ +# This file contains all available configuration options +# with their default values. + +# options for analysis running +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 1m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + + # include test files or not, default is true + tests: false + + # list of build tags, all linters use it. Default is empty list. + # build-tags: [] + + # which dirs to skip: issues from them won't be reported; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but default dirs are skipped independently + # from this option's value (see skip-dirs-use-default). + skip-dirs: + - assets + + # default is true. Enables skipping of directories: + # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ + skip-dirs-use-default: true + + # which files to skip: they will be analyzed, but issues from them + # won't be reported. Default value is empty list, but there is + # no need to include all autogenerated files, we confidently recognize + # autogenerated files. If it's not please let us know. + # skip-files: [] + # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + # modules-download-mode: readonly|release|vendor + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - asciicheck + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - durationcheck + - errcheck + - errorlint + - exhaustive + - exportloopref + - forcetypeassert + - gci + - gochecknoinits + - goconst + - gocritic + - godot + - godox + - goerr113 + - gofmt + - gofumpt + - goheader + - goimports + - gomnd + - gomodguard + - goprintffuncname + - gosec + - gosimple + - govet + - ifshort + - importas + - ineffassign + - lll + - makezero + - misspell + - nakedret + - nestif + - nilerr + - nlreturn + - noctx + - nolintlint + - paralleltest + - prealloc + - predeclared + - revive + - rowserrcheck + - sqlclosecheck + - staticcheck + - structcheck + - stylecheck + - testpackage + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - unused + - varcheck + - wastedassign + - whitespace + - wrapcheck + - wsl + + # ==> don't enable: + # - cyclop + # - forbidigo + # - funlen + # - gochecknoglobals + # - gocognit + # - gocyclo + + # ==> deprecated and will be removed soon: + # - exhaustivestruct + # - interfacer + # - maligned + +# output configuration options +output: + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: colored-line-number + + # print lines of code with issue, default is true + print-issued-lines: true + + # print linter name in the end of issue text, default is true + print-linter-name: true + +# all available settings of specific linters +linters-settings: + # asciicheck: + # bodyclose: + # deadcode: + + depguard: + list-type: blacklist + include-go-root: true + packages-with-error-messages: + github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" + + dogsled: + # checks assignments with too many blank identifiers; default is 2 + max-blank-identifiers: 2 + + dupl: + # tokens count to trigger issue, 150 by default + threshold: 100 + + # durationcheck: + + errcheck: + # report about not checking of errors in type assetions: `a := b.(MyStruct)`; + # default is false: such cases aren't reported by default. + check-type-assertions: false + + # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; + # default is false: such cases aren't reported by default. + check-blank: false + + # path to a file containing a list of functions to exclude from checking + # see https://github.com/kisielk/errcheck#excluding-functions for details + # exclude: /path/to/file.txt + + # errorlint: + # exhaustive: + # exportloopref: + # forcetypeassert: + + # funlen: + # lines: 120 + # statements: 85 + + # gci: + # gochecknoinits: + + goconst: + # minimal length of string constant, 3 by default + min-len: 2 + # minimal occurrences count to trigger, 3 by default + min-occurrences: 2 + + gocritic: + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + + # Which checks should be enabled; can't be combined with 'disabled-checks'; + # See https://go-critic.github.io/overview#checks-overview + # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` + # By default list of stable checks is used. + # enabled-checks: + # - rangeValCopy + + # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty + disabled-checks: + - wrapperFunc + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + + settings: # settings passed to gocritic + captLocal: # must be valid enabled check name + paramsOnly: true + rangeValCopy: + sizeThreshold: 32 + + # godot: + + godox: + # report any comments starting with keywords, this is useful for TODO or FIXME comments that + # might be left in the code accidentally and should be resolved before merging + keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting + - BUG + - FIXME + - HACK + - NOTE + - OPTIMIZE + - TODO + - "@todo" + + # goerr113: + + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true + + # gofumpt: + # goheader: + + goimports: + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: github.com/skyzyx,github.com/northwood-labs + + golint: + # minimal confidence for issues, default is 0.8 + min-confidence: 0 + + # gomnd: + # gomodguard: + # goprintffuncname: + # gosec: + # gosimple: + + govet: + # report about shadowed variables + check-shadowing: true + + # settings per analyzer + # run `go tool vet help` to see all analyzers + # run `go tool vet help printf` to see available settings for `printf` analyzer + settings: + asmdecl: {} + assign: {} + atomic: {} + bools: {} + buildtag: {} + composites: + whitelist: true + copylocks: {} + # errorsas: {} + loopclosure: {} + lostcancel: {} + nilfunc: {} + printf: + funcs: true + shift: {} + stdmethods: {} + structtag: {} + unmarshal: {} + unreachable: {} + unsafeptr: {} + unusedresult: + funcs: true + stringmethods: true + + # ifshort: + # importas: + # ineffassign: + + lll: + # max line length, lines longer will be reported. Default is 120. + # '\t' is counted as 1 character by default, and can be changed with the tab-width option + line-length: 120 + # tab width in spaces. Default to 1. + tab-width: 1 + + # makezero: + + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US + # ignore-words: + # - someword + + nakedret: + # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 + max-func-lines: 30 + + nestif: + min-complexity: 10 + + # nilerr: + # nlreturn: + # noctx: + # nolintlint: + # paralleltest: + # prealloc: + # predeclared: + # revive: + # rowserrcheck: + # staticcheck: + # structcheck: + # stylecheck: + # testpackage: + # thelper: + # tparallel: + # typecheck: + # unconvert: + + unparam: + # Inspect exported functions, default is false. Set to true if no external program/library imports your code. + # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find external interfaces. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: true + + # varcheck: + # wastedassign: + + whitespace: + multi-if: false # Enforces newlines (or comments) after every multi-line if statement + multi-func: false # Enforces newlines (or comments) after every multi-line function signature + + # wrapcheck: + wsl: + # If true append is only allowed to be cuddled if appending value is + # matching variables, fields or types on line above. Default is true. + strict-append: true + + # Allow calls and assignments to be cuddled as long as the lines have any + # matching variables, fields or types. Default is true. + allow-assign-and-call: true + + # Allow multiline assignments to be cuddled. Default is true. + allow-multiline-assign: true + + # Allow declarations (var) to be cuddled. + allow-cuddle-declarations: false + + # Allow trailing comments in ending of blocks + allow-trailing-comment: false + + # Force newlines in end of case at this limit (0 = never). + force-case-trailing-whitespace: 0 + + # Force cuddling of err checks with err var assignment + force-err-cuddling: true + + # Allow leading comments to be separated with empty liens + allow-separated-leading-comment: false + +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + exclude: + - "should have a package comment" + - 'declaration of "(err|ctx)" shadows declaration at' + - "`Println` arg list ends with redundant newline" + - "Println arg list ends with redundant newline" + - "type jsonschema.Schema has no field or method ValidateBytes" + - "declarations should never be cuddled" + - "unnamedResult: consider giving a name to these results" + + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - linters: + - lll + source: "lint:ignore_length" + + - linters: + - gosec + source: "lint:allow_666" + + - linters: + - gosec + source: "lint:allow_possible_insecure" + + - linters: + - unparam + source: "lint:allow_param" + + - linters: + - deadcode + - unused + source: "lint:allow_dead" + + - linters: + - gomnd + source: "lint:allow_raw_number" + + - linters: + - gocritic + source: "lint:ignore_criticism" + + - linters: + - nestif + source: "lint:allow_nesting" + + - linters: + - dupl + source: "lint:no_dupe" + + - linters: + - wsl + source: "lint:allow_cuddling" + + - linters: + - goerr113 + source: "lint:allow_errorf" + + - linters: + - wrapcheck + source: "lint:allow_unwrapped_errors" + + - text: "(SA1019|G402)" + linters: + - staticcheck + - gosec + source: "lint:allow_tls_min_version" + + - text: "(G404)" + linters: + - gosec + source: "lint:not_crypto" + + - text: "(hugeParam)" + linters: + - gocritic + source: "lint:allow_large_memory" + + # Independently from option `exclude` we use default exclude patterns, + # it can be disabled by this option. To list all + # excluded by default patterns execute `golangci-lint run --help`. + # Default value for this option is true. + exclude-use-default: false + + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # Show only new issues: if there are unstaged changes or untracked files, + # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # It's a super-useful option for integration of golangci-lint into existing + # large codebase. It's not practical to fix all existing issues at the moment + # of integration: much better don't allow issues in new code. + # Default is false. + new: false + # Show only new issues created after git revision `REV` + # new-from-rev: REV + # Show only new issues created in git patch with set file path. + # new-from-patch: path/to/patch/file diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..385ec0a --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,113 @@ +{ + "heading-increment": false, + "first-header-h1": true, + "header-style": { + "style": "atx" + }, + "ul-style": { + "style": "asterisk" + }, + "list-indent": true, + "ul-start-left": true, + "ul-indent": { + "indent": 4 + }, + "no-trailing-spaces": { + "br_spaces": 2, + "list_item_empty_lines": false + }, + "single-trailing-newline": true, + "no-hard-tabs": { + "code_blocks": false + }, + "no-reversed-links": true, + "no-multiple-blanks": { + "maximum": 1 + }, + "line-length": { + "line_length": 10000, + "code_blocks": false, + "tables": false + }, + "commands-show-output": false, + "no-missing-space-atx": true, + "no-multiple-space-atx": true, + "blanks-around-headers": { + "lines_above": 1, + "lines_below": 1 + }, + "header-start-left": true, + "no-duplicate-header": { + "allow_different_nesting": true + }, + "single-h1": { + "level": 1 + }, + "no-trailing-punctuation": { + "punctuation": ".,;:" + }, + "no-multiple-space-blockquote": true, + "no-blanks-blockquote": true, + "ol-prefix": { + "style": "one" + }, + "list-marker-space": { + "ul_single": 1, + "ol_single": 1, + "ul_multi": 1, + "ol_multi": 1 + }, + "blanks-around-fences": { + "list_items": true + }, + "blanks-around-lists": true, + "no-inline-html": { + "allowed_elements": [ + "a", + "b", + "br", + "code", + "details", + "div", + "img", + "li", + "nobr", + "p", + "pre", + "summary", + "ul" + ] + }, + "no-bare-urls": true, + "hr-style": { + "style": "consistent" + }, + "no-emphasis-as-header": true, + "no-space-in-emphasis": false, + "no-space-in-code": false, + "no-space-in-links": true, + "fenced-code-language": true, + "code-block-style": { + "style": "fenced" + }, + "first-line-h1": false, + "no-empty-links": true, + "proper-names": { + "names": [ + "Bash", + "Docker", + "Dockerfile", + "EditorConfig", + "Git", + "GitHub", + "Golang", + "JavaScript", + "macOS", + "Node", + "Node.js", + "npm", + "PHP" + ], + "code_blocks": false + } +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..6535c4a --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,53 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "aleksandra.go-group-imports", + "amazonwebservices.aws-toolkit-vscode", + "annsk.alignment", + "bierner.markdown-preview-github-styles", + "bin3377.iam-policy", + "christian-kohler.path-intellisense", + "cmacu.gotoanything", + "codezombiech.gitignore", + "darkriszty.markdown-table-prettify", + "davidanson.vscode-markdownlint", + "deerawan.vscode-dash", + "donjayamanne.githistory", + "eamodio.gitlens", + "editorconfig.editorconfig", + "fcrespo82.markdown-table-formatter", + "foxundermoon.shell-format", + "golang.go", + "gruntfuggly.todo-tree", + "gurumukhi.selected-lines-count", + "hashicorp.terraform", + "hcltechnologies.hclappscancodesweep", + "jfrog.jfrog-vscode-extension", + "lamartire.git-indicators", + "mads-hartmann.bash-ide-vscode", + "mohsen1.prettify-json", + "ms-python.python", + "ms-python.vscode-pylance", + "msyrus.go-doc", + "neverik.go-critic", + "quicktype.quicktype", + "rogalmic.bash-debug", + "sonarsource.sonarlint-vscode", + "steefh.terraform-documentation-links", + "stkb.rewrap", + "timonwong.shellcheck", + "tyriar.sort-lines", + "usernamehw.errorlens", + "visualstudioexptteam.vscodeintellicode", + "yzhang.markdown-all-in-one", + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [ + "googlecloudtools.cloudcode", + "mindaro.mindaro", + "ms-azuretools.vscode-azureterraform", + "ms-kubernetes-tools.vscode-kubernetes-tools", + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..32075c6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,61 @@ +{ + "alignment.chars": { + ":": { + "spaceBefore": 0, + "spaceAfter": 1 + }, + "::": { + "spaceBefore": 0, + "spaceAfter": 0 + }, + "=": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "===": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "==": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "=>": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "+=": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "-=": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "*=": { + "spaceBefore": 1, + "spaceAfter": 1 + }, + "/=": { + "spaceBefore": 1, + "spaceAfter": 1 + } + }, + "diffEditor.codeLens": true, + "files.autoSave": "onWindowChange", + "files.defaultLanguage": "${activeEditorLanguage}", + "files.eol": "\n", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true, + "problems.showCurrentInStatus": true, + "python.formatting.provider": "yapf", + "search.showLineNumbers": true, + "search.useGlobalIgnoreFiles": true, + "[terraform]": { + "editor.formatOnSave": true + }, + "terraform-ls.experimentalFeatures": { + "validateOnSave": true + } +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1460a42 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1-alpine + +RUN apk add --no-cache make nodejs wget + +RUN mkdir -p /workspace +COPY go.mod /workspace +COPY go.sum /workspace +COPY main.go /workspace +COPY Makefile /workspace + +WORKDIR /workspace + +ENTRYPOINT ["make", "build"] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..040291b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +# MIT License + +Copyright 2022 Ryan Parman + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bc7bca6 --- /dev/null +++ b/Makefile @@ -0,0 +1,159 @@ +#------------------------------------------------------------------------------- +# Running `make` will show the list of subcommands that will run. + +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) +current_dir := $(dir $(mkfile_path)) + +#------------------------------------------------------------------------------- +# Global stuff. + +GO=$(shell which go) + +# Determine which version of `echo` to use. Use version from coreutils if available. +ECHOCHECK := $(shell command -v /usr/local/opt/coreutils/libexec/gnubin/echo 2> /dev/null) +ifdef ECHOCHECK + ECHO=/usr/local/opt/coreutils/libexec/gnubin/echo +else + ECHO=echo +endif + +#------------------------------------------------------------------------------- +# Running `make` will show the list of subcommands that will run. + +all: help + +.PHONY: help +## help: [help]* Prints this help message. +help: + @ $(ECHO) "Usage:" + @ $(ECHO) "" + @ sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' | \ + while IFS= read -r line; do \ + if [[ "$$line" == *"]*"* ]]; then \ + $(ECHO) -e "\033[1;33m$$line\033[0m"; \ + else \ + $(ECHO) "$$line"; \ + fi; \ + done + +#------------------------------------------------------------------------------- +# Install + +# Private +.PHONY: _install-go-deps +_install-go-deps: + $(GO) install github.com/quasilyte/go-consistent@latest + $(GO) install github.com/jgautheron/goconst/cmd/goconst@latest + $(GO) install mvdan.cc/gofumpt@latest + $(GO) install github.com/pavius/impi/cmd/impi@latest + +.PHONY: install-deps-linux +## install-deps-linux: [deps]* Installs the tools for Linux. +install-deps-linux: _install-go-deps + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin + +.PHONY: install-deps-mac +## install-deps-mac: [deps]* Installs the tools for macOS. Requires Homebrew. +install-deps-mac: _install-go-deps + brew install golangci-lint + +#------------------------------------------------------------------------------- +# Build/Run + +.PHONY: fetch +## fetch: [build] Fetches remote data that is required for building. +fetch: + wget -qq https://data.iana.org/TLD/tlds-alpha-by-domain.txt + +.PHONY: tidy +## tidy: [build] Updates go.mod and downloads dependencies. +tidy: + $(GO) mod tidy -go=1.17 -v + $(GO) mod download -x + $(GO) get -v ./... + +.PHONY: generate +## generate: [build] Reads the raw list and generates a UTF-8 JSON document. +generate: + go run main.go | tee tlds.json + +.PHONY: build +## build: [build]* Compiles the final artifacts. +build: fetch generate clean-files + +#------------------------------------------------------------------------------- +# Clean + +.PHONY: clean-files +## clean-files: [clean] Clean temporary files. +clean-files: + rm -f tlds-alpha-by-domain.txt + +.PHONY: clean-go +## clean-go: [clean] Clean Go's module cache. +clean-go: + $(GO) clean -i -r -x -testcache -modcache -cache + +.PHONY: clean +## clean: [clean]* Runs ALL non-Golang cleaning tasks. +clean: clean-files + +#------------------------------------------------------------------------------- +# Linting + +.PHONY: fmt +## fmt: [lint] Runs `gofumpt` against all Golang files. +fmt: + @ echo " " + @ echo "=====> Running gofumpt..." + gofumpt -s -w *.go + +.PHONY: golint +## golint: [lint] Runs `golangci-lint` against all Golang files. +golint: + @ echo " " + @ echo "=====> Running golangci-lint..." + golangci-lint run --fix *.go + +.PHONY: goupdate +## goupdate: [lint] Runs `go-mod-outdated` to check for out-of-date packages. +goupdate: + @ echo " " + @ echo "=====> Running go-mod-outdated..." + $(GO) list -u -m -json all | go-mod-outdated -update -direct -style markdown + +.PHONY: goconsistent +## goconsistent: [lint] Runs `go-consistent` to ensure consistent patterns. +goconsistent: + @ echo " " + @ echo "=====> Running go-consistent..." + - go-consistent -v ./... + +.PHONY: goimportorder +## goimportorder: [lint] Runs `impi` to verify that import order is consistent. +goimportorder: + @ echo " " + @ echo "=====> Running impi..." + - impi \ + --local $(shell head -n1 < go.mod | cut -d' ' -f2) \ + --ignore-generated=true \ + --scheme=stdLocalThirdParty \ + ./... + +.PHONY: goconst +## goconst: [lint] Runs `goconst` to identify opportunities for constants. +goconst: + @ echo " " + @ echo "=====> Running goconst..." + - goconst -match-constant -numbers ./... + +.PHONY: markdownlint +## markdownlint: [lint] Runs `markdownlint` against all Markdown documents. +markdownlint: + @ echo " " + @ echo "=====> Running Markdownlint..." + - npx -y markdownlint-cli --fix '*.md' --ignore 'node_modules' + +.PHONY: lint +## lint: [lint]* Runs ALL linting/validation tasks. +lint: markdownlint fmt golint goupdate goimportorder goconst diff --git a/README.md b/README.md new file mode 100644 index 0000000..2fc5427 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# IANA TLD List + +List of TLDs from [ICANN](https://www.icann.org/resources/pages/tlds-2012-02-25-en). + +## Usage + +Grab the `tlds.json` file from this repo and use it however you want. + +## Building without Developing + +* Docker Engine + Docker Compose (both come with Docker Desktop) + +```bash +docker compose up +``` + +## Local Development + +* Go (run the generator) +* wget (download the data from IANA) +* make (facilitate simple build steps) +* Node.js (for running `markdownlint`) + +View all available tasks: + +```bash +make +``` + +Build your very own copy: + +```bash +make build +``` + +## Authorship and Licensing + +Code authored by Ryan Parman. The Go code, `Dockerfile`, and other "development-y" things are made available under the MIT License. + +The TLD list itself (including the JSON-formatted `tlds.json` file) are made available under the terms listed in [IANA: Licensing Terms](https://www.iana.org/help/licensing-terms), which states either _public domain_ or the [Creative Commons CC0 1.0 Universal (CC0 1.0): Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/legalcode) license. + +## Inspiration + +This is a port of the generation bits of [`stephenmathieson/node-tlds`](https://github.com/stephenmathieson/node-tlds) to Go. The original package suffers from the issues discussed in “[NPM & left-pad: Have We Forgotten How To Program?](https://www.davidhaney.io/npm-left-pad-have-we-forgotten-how-to-program/)”, including depending on multiple third-party packages that are utterly unnecessary — even in JavaScript/Node.js. + +I wanted to provide something more reliable, with no dependencies outside the standard library. diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..5040986 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,8 @@ +services: + builder: + build: + context: . + dockerfile: Dockerfile + container_name: iana-tlds + volumes: + - $PWD:/workspace:rw diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..025b38d --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/skyzyx/iana-tlds + +go 1.17 + +require golang.org/x/net v0.0.0-20220412020605-290c469a71a5 + +require golang.org/x/text v0.3.7 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..35c3858 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4= +golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..5940739 --- /dev/null +++ b/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "os" + "regexp" + "sort" + "strings" + + "golang.org/x/net/idna" +) + +const ( + filename = "tlds-alpha-by-domain.txt" +) + +var ( + punycodeRE = regexp.MustCompile(`(?i)xn--[a-z0-9]+`) + puny = idna.New() +) + +func main() { + content, err := os.ReadFile(filename) + if err != nil { + log.Fatal(err) + } + + tldsRaw := strings.Split(string(content), "\n") + tldsRaw = tldsRaw[1 : len(tldsRaw)-1] + + tldsRaw = mapper(tldsRaw, func(s string) string { + s = strings.ToLower(s) + + if isPunyCode(s) { + s, err = puny.ToUnicode(s) + if err != nil { + log.Fatal(err) + } + } + + return s + }) + + sort.Strings(tldsRaw) + + b, err := json.Marshal(tldsRaw) + if err != nil { + log.Fatal(err) + } + + fmt.Println(string(b)) +} + +func mapper(vs []string, f func(string) string) []string { + vsm := make([]string, len(vs)) + + for i, v := range vs { + vsm[i] = f(v) + } + + return vsm +} + +func isPunyCode(str string) bool { + return punycodeRE.MatchString(str) +} diff --git a/tlds.json b/tlds.json new file mode 100644 index 0000000..e619787 --- /dev/null +++ b/tlds.json @@ -0,0 +1 @@ +["aaa","aarp","abarth","abb","abbott","abbvie","abc","able","abogado","abudhabi","ac","academy","accenture","accountant","accountants","aco","actor","ad","adac","ads","adult","ae","aeg","aero","aetna","af","afl","africa","ag","agakhan","agency","ai","aig","airbus","airforce","airtel","akdn","al","alfaromeo","alibaba","alipay","allfinanz","allstate","ally","alsace","alstom","am","amazon","americanexpress","americanfamily","amex","amfam","amica","amsterdam","analytics","android","anquan","anz","ao","aol","apartments","app","apple","aq","aquarelle","ar","arab","aramco","archi","army","arpa","art","arte","as","asda","asia","associates","at","athleta","attorney","au","auction","audi","audible","audio","auspost","author","auto","autos","avianca","aw","aws","ax","axa","az","azure","ba","baby","baidu","banamex","bananarepublic","band","bank","bar","barcelona","barclaycard","barclays","barefoot","bargains","baseball","basketball","bauhaus","bayern","bb","bbc","bbt","bbva","bcg","bcn","bd","be","beats","beauty","beer","bentley","berlin","best","bestbuy","bet","bf","bg","bh","bharti","bi","bible","bid","bike","bing","bingo","bio","biz","bj","black","blackfriday","blockbuster","blog","bloomberg","blue","bm","bms","bmw","bn","bnpparibas","bo","boats","boehringer","bofa","bom","bond","boo","book","booking","bosch","bostik","boston","bot","boutique","box","br","bradesco","bridgestone","broadway","broker","brother","brussels","bs","bt","bugatti","build","builders","business","buy","buzz","bv","bw","by","bz","bzh","ca","cab","cafe","cal","call","calvinklein","cam","camera","camp","cancerresearch","canon","capetown","capital","capitalone","car","caravan","cards","care","career","careers","cars","casa","case","cash","casino","cat","catering","catholic","cba","cbn","cbre","cbs","cc","cd","center","ceo","cern","cf","cfa","cfd","cg","ch","chanel","channel","charity","chase","chat","cheap","chintai","christmas","chrome","church","ci","cipriani","circle","cisco","citadel","citi","citic","city","cityeats","ck","cl","claims","cleaning","click","clinic","clinique","clothing","cloud","club","clubmed","cm","cn","co","coach","codes","coffee","college","cologne","com","comcast","commbank","community","company","compare","computer","comsec","condos","construction","consulting","contact","contractors","cooking","cookingchannel","cool","coop","corsica","country","coupon","coupons","courses","cpa","cr","credit","creditcard","creditunion","cricket","crown","crs","cruise","cruises","cu","cuisinella","cv","cw","cx","cy","cymru","cyou","cz","dabur","dad","dance","data","date","dating","datsun","day","dclk","dds","de","deal","dealer","deals","degree","delivery","dell","deloitte","delta","democrat","dental","dentist","desi","design","dev","dhl","diamonds","diet","digital","direct","directory","discount","discover","dish","diy","dj","dk","dm","dnp","do","docs","doctor","dog","domains","dot","download","drive","dtv","dubai","dunlop","dupont","durban","dvag","dvr","dz","earth","eat","ec","eco","edeka","edu","education","ee","eg","email","emerck","energy","engineer","engineering","enterprises","epson","equipment","er","ericsson","erni","es","esq","estate","et","etisalat","eu","eurovision","eus","events","exchange","expert","exposed","express","extraspace","fage","fail","fairwinds","faith","family","fan","fans","farm","farmers","fashion","fast","fedex","feedback","ferrari","ferrero","fi","fiat","fidelity","fido","film","final","finance","financial","fire","firestone","firmdale","fish","fishing","fit","fitness","fj","fk","flickr","flights","flir","florist","flowers","fly","fm","fo","foo","food","foodnetwork","football","ford","forex","forsale","forum","foundation","fox","fr","free","fresenius","frl","frogans","frontdoor","frontier","ftr","fujitsu","fun","fund","furniture","futbol","fyi","ga","gal","gallery","gallo","gallup","game","games","gap","garden","gay","gb","gbiz","gd","gdn","ge","gea","gent","genting","george","gf","gg","ggee","gh","gi","gift","gifts","gives","giving","gl","glass","gle","global","globo","gm","gmail","gmbh","gmo","gmx","gn","godaddy","gold","goldpoint","golf","goo","goodyear","goog","google","gop","got","gov","gp","gq","gr","grainger","graphics","gratis","green","gripe","grocery","group","gs","gt","gu","guardian","gucci","guge","guide","guitars","guru","gw","gy","hair","hamburg","hangout","haus","hbo","hdfc","hdfcbank","health","healthcare","help","helsinki","here","hermes","hgtv","hiphop","hisamitsu","hitachi","hiv","hk","hkt","hm","hn","hockey","holdings","holiday","homedepot","homegoods","homes","homesense","honda","horse","hospital","host","hosting","hot","hoteles","hotels","hotmail","house","how","hr","hsbc","ht","hu","hughes","hyatt","hyundai","ibm","icbc","ice","icu","id","ie","ieee","ifm","ikano","il","im","imamat","imdb","immo","immobilien","in","inc","industries","infiniti","info","ing","ink","institute","insurance","insure","int","international","intuit","investments","io","ipiranga","iq","ir","irish","is","ismaili","ist","istanbul","it","itau","itv","jaguar","java","jcb","je","jeep","jetzt","jewelry","jio","jll","jm","jmp","jnj","jo","jobs","joburg","jot","joy","jp","jpmorgan","jprs","juegos","juniper","kaufen","kddi","ke","kerryhotels","kerrylogistics","kerryproperties","kfh","kg","kh","ki","kia","kids","kim","kinder","kindle","kitchen","kiwi","km","kn","koeln","komatsu","kosher","kp","kpmg","kpn","kr","krd","kred","kuokgroup","kw","ky","kyoto","kz","la","lacaixa","lamborghini","lamer","lancaster","lancia","land","landrover","lanxess","lasalle","lat","latino","latrobe","law","lawyer","lb","lc","lds","lease","leclerc","lefrak","legal","lego","lexus","lgbt","li","lidl","life","lifeinsurance","lifestyle","lighting","like","lilly","limited","limo","lincoln","linde","link","lipsy","live","living","lk","llc","llp","loan","loans","locker","locus","loft","lol","london","lotte","lotto","love","lpl","lplfinancial","lr","ls","lt","ltd","ltda","lu","lundbeck","luxe","luxury","lv","ly","ma","macys","madrid","maif","maison","makeup","man","management","mango","map","market","marketing","markets","marriott","marshalls","maserati","mattel","mba","mc","mckinsey","md","me","med","media","meet","melbourne","meme","memorial","men","menu","merckmsd","mg","mh","miami","microsoft","mil","mini","mint","mit","mitsubishi","mk","ml","mlb","mls","mm","mma","mn","mo","mobi","mobile","moda","moe","moi","mom","monash","money","monster","mormon","mortgage","moscow","moto","motorcycles","mov","movie","mp","mq","mr","ms","msd","mt","mtn","mtr","mu","museum","music","mutual","mv","mw","mx","my","mz","na","nab","nagoya","name","natura","navy","nba","nc","ne","nec","net","netbank","netflix","network","neustar","new","news","next","nextdirect","nexus","nf","nfl","ng","ngo","nhk","ni","nico","nike","nikon","ninja","nissan","nissay","nl","no","nokia","northwesternmutual","norton","now","nowruz","nowtv","np","nr","nra","nrw","ntt","nu","nyc","nz","obi","observer","office","okinawa","olayan","olayangroup","oldnavy","ollo","om","omega","one","ong","onl","online","ooo","open","oracle","orange","org","organic","origins","osaka","otsuka","ott","ovh","pa","page","panasonic","paris","pars","partners","parts","party","passagens","pay","pccw","pe","pet","pf","pfizer","pg","ph","pharmacy","phd","philips","phone","photo","photography","photos","physio","pics","pictet","pictures","pid","pin","ping","pink","pioneer","pizza","pk","pl","place","play","playstation","plumbing","plus","pm","pn","pnc","pohl","poker","politie","porn","post","pr","pramerica","praxi","press","prime","pro","prod","productions","prof","progressive","promo","properties","property","protection","pru","prudential","ps","pt","pub","pw","pwc","py","qa","qpon","quebec","quest","racing","radio","re","read","realestate","realtor","realty","recipes","red","redstone","redumbrella","rehab","reise","reisen","reit","reliance","ren","rent","rentals","repair","report","republican","rest","restaurant","review","reviews","rexroth","rich","richardli","ricoh","ril","rio","rip","ro","rocher","rocks","rodeo","rogers","room","rs","rsvp","ru","rugby","ruhr","run","rw","rwe","ryukyu","sa","saarland","safe","safety","sakura","sale","salon","samsclub","samsung","sandvik","sandvikcoromant","sanofi","sap","sarl","sas","save","saxo","sb","sbi","sbs","sc","sca","scb","schaeffler","schmidt","scholarships","school","schule","schwarz","science","scot","sd","se","search","seat","secure","security","seek","select","sener","services","ses","seven","sew","sex","sexy","sfr","sg","sh","shangrila","sharp","shaw","shell","shia","shiksha","shoes","shop","shopping","shouji","show","showtime","si","silk","sina","singles","site","sj","sk","ski","skin","sky","skype","sl","sling","sm","smart","smile","sn","sncf","so","soccer","social","softbank","software","sohu","solar","solutions","song","sony","soy","spa","space","sport","spot","sr","srl","ss","st","stada","staples","star","statebank","statefarm","stc","stcgroup","stockholm","storage","store","stream","studio","study","style","su","sucks","supplies","supply","support","surf","surgery","suzuki","sv","swatch","swiss","sx","sy","sydney","systems","sz","tab","taipei","talk","taobao","target","tatamotors","tatar","tattoo","tax","taxi","tc","tci","td","tdk","team","tech","technology","tel","temasek","tennis","teva","tf","tg","th","thd","theater","theatre","tiaa","tickets","tienda","tiffany","tips","tires","tirol","tj","tjmaxx","tjx","tk","tkmaxx","tl","tm","tmall","tn","to","today","tokyo","tools","top","toray","toshiba","total","tours","town","toyota","toys","tr","trade","trading","training","travel","travelchannel","travelers","travelersinsurance","trust","trv","tt","tube","tui","tunes","tushu","tv","tvs","tw","tz","ua","ubank","ubs","ug","uk","unicom","university","uno","uol","ups","us","uy","uz","va","vacations","vana","vanguard","vc","ve","vegas","ventures","verisign","vermögensberater","vermögensberatung","versicherung","vet","vg","vi","viajes","video","vig","viking","villas","vin","vip","virgin","visa","vision","viva","vivo","vlaanderen","vn","vodka","volkswagen","volvo","vote","voting","voto","voyage","vu","vuelos","wales","walmart","walter","wang","wanggou","watch","watches","weather","weatherchannel","webcam","weber","website","wed","wedding","weibo","weir","wf","whoswho","wien","wiki","williamhill","win","windows","wine","winners","wme","wolterskluwer","woodside","work","works","world","wow","ws","wtc","wtf","xbox","xerox","xfinity","xihuan","xin","xxx","xyz","yachts","yahoo","yamaxun","yandex","ye","yodobashi","yoga","yokohama","you","youtube","yt","yun","za","zappos","zara","zero","zip","zm","zone","zuerich","zw","ελ","ευ","бг","бел","дети","ею","католик","ком","мкд","мон","москва","онлайн","орг","рус","рф","сайт","срб","укр","қаз","հայ","ישראל","קום","ابوظبي","اتصالات","ارامكو","الاردن","البحرين","الجزائر","السعودية","العليان","المغرب","امارات","ایران","بارت","بازار","بيتك","بھارت","تونس","سودان","سورية","شبكة","عراق","عرب","عمان","فلسطين","قطر","كاثوليك","كوم","مصر","مليسيا","موريتانيا","موقع","همراه","پاکستان","ڀارت","कॉम","नेट","भारत","भारतम्","भारोत","संगठन","বাংলা","ভারত","ভাৰত","ਭਾਰਤ","ભારત","ଭାରତ","இந்தியா","இலங்கை","சிங்கப்பூர்","భారత్","ಭಾರತ","ഭാരതം","ලංකා","คอม","ไทย","ລາວ","გე","みんな","アマゾン","クラウド","グーグル","コム","ストア","セール","ファッション","ポイント","世界","中信","中国","中國","中文网","亚马逊","企业","佛山","信息","健康","八卦","公司","公益","台湾","台灣","商城","商店","商标","嘉里","嘉里大酒店","在线","大拿","天主教","娱乐","家電","广东","微博","慈善","我爱你","手机","招聘","政务","政府","新加坡","新闻","时尚","書籍","机构","淡马锡","游戏","澳門","点看","移动","组织机构","网址","网店","网站","网络","联通","诺基亚","谷歌","购物","通販","集团","電訊盈科","飞利浦","食品","餐厅","香格里拉","香港","닷넷","닷컴","삼성","한국"]