-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
63 lines (49 loc) · 1.45 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"database/sql"
"fmt"
"os"
)
func getEnv(envKey string) (envValue string, err error) {
envValue, ok := os.LookupEnv(envKey)
if ok != true {
err = fmt.Errorf("please set %s environment variable", envKey)
return
}
return envValue, nil
}
func dbConnection() (*sql.DB, error) {
username, err := getEnv("MYSQL_USERNAME")
if err != nil {
return nil, err
}
password, err := getEnv("MYSQL_PASSWORD")
if err != nil {
return nil, err
}
host, err := getEnv("MYSQL_HOST")
if err != nil {
return nil, err
}
database, err := getEnv("MYSQL_DATABASE")
if err != nil {
return nil, err
}
connection := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", username, password, host, database)
// Open and connect do DB
db, err := sql.Open("mysql", connection)
if err != nil {
return nil, err
}
// Open doesn't open a connection. Validate DSN data:
err = db.Ping()
if err != nil {
return nil, err
}
return db, nil
}
// annotate:artist="Camila Cabello",title="Havana (Nitsuga Remix) / https://soundcloud.com/nitsuga-3/camila-cabello-havana-ft-young-thug-nitsuga-remix",length="229":/MUSIC/BACKUP/remix/puck/Camila_Cabello_-_Havana_(Nitsuga_Remix).mp3
func annotate(artist string, title string, length string, share string, filename string, image string) string {
annotation := fmt.Sprintf(`annotate:artist="%s",title="%s",length="%s",image="%s",share="%s":%s`, artist, title, length, image, share, filename)
return annotation
}