-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (40 loc) · 803 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"bufio"
"fmt"
"io"
"net/url"
"os"
"strings"
)
func readUrls(input io.Reader) ([]*url.URL, error) {
urls := make([]*url.URL, 0)
r := bufio.NewReaderSize(input, 160)
for more := true; more; {
line, rErr := r.ReadString('\n')
if rErr != nil && rErr != io.EOF {
err := fmt.Errorf("failed to read url line: %w", rErr)
return nil, err
}
more = rErr != io.EOF
line = strings.TrimSpace(line)
if line == "" {
continue
}
u, err := url.Parse(line)
if err != nil {
continue
}
urls = append(urls, u)
}
return urls, nil
}
func main() {
urls, err := readUrls(os.Stdin)
if err != nil {
fmt.Printf("Failed to read urls from stdin: %v", err)
os.Exit(1)
}
nConns := MeasureMaxConnections(urls)
fmt.Println("Max connections are", nConns)
}