-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (59 loc) · 1.66 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"net/http"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/mux"
)
// SongDetails to output details of the songs to json
type SongDetails struct {
ID int64 `json:"id"`
Title string `json:"title"`
Artist string `json:"artist"`
Show string `json:"show"`
Image string `json:"image"`
Filename string `json:"filename"`
Album string `json:"album"`
Length string `json:"lenght"`
Share string `json:"share"`
URL string `json:"url"`
Playlist string `json:"playlist"`
}
func init() {
db, err := dbConnection()
if err != nil {
log.Println("Connection to database failed: ", err)
return
}
err = generatePlaylist(db)
if err != nil {
log.Println("Error updating the playlist ", err)
}
}
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "XTRadio Admin.")
log.Println(r.RemoteAddr, r.Method, r.URL)
}
func publishAPI() {
apiRouter := mux.NewRouter().StrictSlash(true)
// apiRouter.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// apiRouter.HandleFunc("/", homePage)
apiRouter.HandleFunc("/search", songSearch)
apiRouter.HandleFunc("/v1/song/list", songList).
Methods("GET")
apiRouter.HandleFunc("/v1/song/upload", songUpload).
Methods("POST")
apiRouter.HandleFunc("/v1/song/update", songUpdate).
Methods("POST")
apiRouter.HandleFunc("/v1/song/queue", songQueue).
Methods("POST")
apiRouter.
PathPrefix("/").
Handler(http.StripPrefix("/", http.FileServer(http.Dir("./static"))))
log.Fatal(http.ListenAndServe(":10000", apiRouter))
}
func main() {
log.Println("Rest API v2.0 - Mux Routers")
publishAPI()
}