Created
December 27, 2022 11:52
-
-
Save bontusss/843f81321de939ed46a71b3ffb806143 to your computer and use it in GitHub Desktop.
Domainify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"math/rand" | |
"os" | |
"strings" | |
"time" | |
"unicode" | |
) | |
var tlds = []string{"com", "net"} | |
const allowedChars = "abcdwfghijklmnopqrstuvwxyz012346789_-" | |
func main() { | |
rand.Seed(time.Now().UTC().UnixNano()) | |
s:= bufio.NewScanner(os.Stdin) | |
for s.Scan() { | |
text := strings.ToLower(s.Text()) | |
var newText []rune | |
for _, r := range text { | |
if unicode.IsSpace(r) { | |
r = '-' | |
} | |
if !strings.ContainsRune(allowedChars, r) { | |
continue | |
} | |
newText = append(newText, r) | |
} | |
fmt.Println(string(newText) + "." + tlds[rand.Intn(len(tlds))]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment