-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.go
50 lines (38 loc) · 861 Bytes
/
utils.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
package gomusixmatch
import (
"net/url"
"os"
"strings"
mxmParams "github.com/milindmadhukar/go-musixmatch/params"
)
func processParams(musixMatchUrl string, params ...mxmParams.Param) (string, error) {
p := mxmParams.Params{
UrlParams: url.Values{},
}
for _, param := range params {
param(&p)
if p.Err != nil {
return "", p.Err
}
}
urlParams := p.UrlParams.Encode()
if urlParams != "" {
musixMatchUrl += "&" + urlParams
}
return musixMatchUrl, nil
}
func GetApiKeyFromEnvFile(filename string) string {
file, err := os.ReadFile(filename)
if err != nil {
panic(err)
}
content := string(file)
lines := strings.Split(content, "\n")
for _, line := range lines {
if strings.Contains(line, "MUSIXMATCH_API_KEY") {
apiKey := strings.Split(line, "=")
return apiKey[1]
}
}
panic("API Key not found in the file")
}