Really lucked out here that .gov is explicitly enumerated in a published list. For basically any other TLD your first (big!) issue will be finding such a list.