-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
31 lines (24 loc) · 675 Bytes
/
api.go
File metadata and controls
31 lines (24 loc) · 675 Bytes
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
package main
import (
"crypto/rand"
"io/ioutil"
"math/big"
"net/http"
"strconv"
)
func request() (string, int) {
client := &http.Client{}
var max = 1000
rndm, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
rndmInt := int(rndm.Uint64())
var song_id string = strconv.Itoa(rndmInt)
req, err := http.NewRequest(http.MethodGet, "https://api.genius.com/songs/" + song_id, nil)
CheckError(err)
req.Header.Add("Authorization", "Bearer TKqINJxo3mdqtcIlf7ChIjCDLewQLpX5hCg831FReTOvpKKXio098yqrkr19TX6o")
resp, err := client.Do(req)
CheckError(err)
body, err := ioutil.ReadAll(resp.Body)
CheckError(err)
resp.Body.Close()
return string(body[:]), rndmInt
}