This commit is contained in:
Melvin Lammerts
2022-08-21 20:25:06 +02:00
parent ec8ccdca07
commit 555a14d2b6
2 changed files with 44 additions and 0 deletions

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/melvinsh/unhttpx
go 1.19

41
main.go Normal file
View File

@@ -0,0 +1,41 @@
package main
import (
"bufio"
"fmt"
"log"
"net/url"
"os"
)
func main() {
var urls []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
u := scanner.Text()
if u != "" {
urls = append(urls, u)
}
}
if err := scanner.Err(); err != nil {
log.Println(err)
}
for _, url := range urls {
fmt.Println(host(url))
}
}
func host(u string) string {
parsed, err := url.Parse(u)
if err != nil {
return u
}
return parsed.Host
}