This repository has been archived by the owner on Sep 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
98 lines (86 loc) · 2.16 KB
/
generate.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"encoding/json"
"fmt"
"github.com/Bejdenn/url-shortener/functions/url-shortening/url"
"io/ioutil"
"log"
"math/rand"
"net/http"
"strings"
)
func main() {
addresses := []string{
"http://www.facebook.com",
"http://www.baidu.com",
"http://www.yahoo.com",
"http://www.amazon.com",
"http://www.wikipedia.org",
"http://www.taobao.com",
"http://www.instagram.com",
"http://www.sina.com.cn",
"http://www.yahoo.co.jp",
"http://www.yandex.ru",
"http://www.hao123.com",
"http://www.ebay.com",
"http://www.tmall.com",
"http://www.amazon.co.jp",
"http://www.paypal.com",
"http://www.stackoverflow.com",
"http://www.aliexpress.com",
"http://www.naver.com",
"http://www.apple.com",
"http://www.chinadaily.com.cn",
"http://www.google.ca",
"http://www.whatsapp.com",
"http://www.amazon.in",
"http://www.tianya.cn",
"http://www.rakuten.co.jp",
"http://www.craigslist.org",
"http://www.amazon.de",
"http://www.xinhuanet.com",
"http://www.outbrain.com",
"http://www.alibaba.com",
"http://www.alipay.com",
"http://www.google.com.au",
"http://www.popads.net",
"http://www.amazon.co.uk",
"http://www.wikia.com",
"http://www.googleadservices.com",
"http://www.accuweather.com",
"http://www.answers.yahoo.com",
}
relations := make([]*url.Relation, 0)
for _, addr := range addresses {
for i := 0; i < rand.Intn(25)+1; i++ {
api := "https://api-72ey6bex.nw.gateway.dev/url-shortening"
method := "POST"
payload := strings.NewReader("longUrl=" + addr)
client := &http.Client{}
req, err := http.NewRequest(method, api, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
log.Printf("Request short URL for: %s\n", addr)
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
rel := &url.Relation{}
err = json.Unmarshal(body, rel)
if err != nil {
log.Printf("could not unmarshall response for addr %s: %v", addr, err)
return
}
relations = append(relations, rel)
}
}
}