Skip to content

Instantly share code, notes, and snippets.

@bontusss
Created December 27, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bontusss/843f81321de939ed46a71b3ffb806143 to your computer and use it in GitHub Desktop.
Save bontusss/843f81321de939ed46a71b3ffb806143 to your computer and use it in GitHub Desktop.
Domainify
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