refactor(struct): change file for structs in server.go
This commit is contained in:
parent
1d748b0fec
commit
ea2eed9bf8
2 changed files with 29 additions and 42 deletions
44
server.go
44
server.go
|
@ -10,33 +10,6 @@ import (
|
|||
"github.com/undertideco/bandcamp"
|
||||
)
|
||||
|
||||
type BandcampAlbum struct {
|
||||
find bool
|
||||
url string
|
||||
}
|
||||
|
||||
type UrlBandcamp struct {
|
||||
Artiste string `json:"artist"`
|
||||
Album string `json:"album"`
|
||||
SpotifyUrl string `json:"spotifyurl"`
|
||||
BandcampUrl string `json:"bandcampurl"`
|
||||
}
|
||||
|
||||
func newUrlBandcamp(auteur, album, spo, band string) UrlBandcamp {
|
||||
return UrlBandcamp{Artiste: auteur, Album: album, SpotifyUrl: spo, BandcampUrl: band}
|
||||
}
|
||||
|
||||
type RespBandcamp struct {
|
||||
Done int `json:"done"`
|
||||
Todo int `json:"todo"`
|
||||
Urls []UrlBandcamp `json:"urls"`
|
||||
}
|
||||
|
||||
func (rp *RespBandcamp) Add(tmp UrlBandcamp) []UrlBandcamp {
|
||||
rp.Urls = append(rp.Urls, tmp)
|
||||
return rp.Urls
|
||||
}
|
||||
|
||||
var MyClient = &http.Client{}
|
||||
var MyResp = &RespBandcamp{}
|
||||
|
||||
|
@ -129,20 +102,12 @@ func formHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
//fmt.Fprintf(w, "POST request successful\n")
|
||||
//type_id := r.FormValue("type-id")
|
||||
//id := r.FormValue("id")
|
||||
|
||||
//fmt.Fprintf(w, "Type ID = %s\n", type_id)
|
||||
//fmt.Fprintf(w, "ID = %s\n", id)
|
||||
|
||||
w.Header().Set("Location", "/feudecamp.html")
|
||||
w.WriteHeader(http.StatusSeeOther)
|
||||
//go getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
|
||||
go getListPlaylist(r.FormValue("id"))
|
||||
}
|
||||
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
func hello(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/hello" {
|
||||
http.Error(w, "404", http.StatusNotFound)
|
||||
return
|
||||
|
@ -156,10 +121,6 @@ func index(w http.ResponseWriter, r *http.Request) {
|
|||
fmt.Fprintf(w, "Helo!")
|
||||
}
|
||||
|
||||
func test(w http.ResponseWriter, r *http.Request) {
|
||||
getListPlaylist("6OGZZ8tI45MB1d3EUEqNKI")
|
||||
}
|
||||
|
||||
func getNew(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
@ -170,9 +131,8 @@ func getNew(w http.ResponseWriter, r *http.Request) {
|
|||
func main() {
|
||||
fileServer := http.FileServer(http.Dir("./static"))
|
||||
http.Handle("/", fileServer)
|
||||
http.HandleFunc("/hello", index)
|
||||
http.HandleFunc("/hello", hello)
|
||||
http.HandleFunc("/back", formHandler)
|
||||
http.HandleFunc("/test", test)
|
||||
http.HandleFunc("/refresh", getNew)
|
||||
|
||||
fmt.Printf("Starting the server…\n")
|
||||
|
|
27
struct.go
27
struct.go
|
@ -2,6 +2,33 @@ package main
|
|||
|
||||
import "time"
|
||||
|
||||
type BandcampAlbum struct {
|
||||
find bool
|
||||
url string
|
||||
}
|
||||
|
||||
type UrlBandcamp struct {
|
||||
Artiste string `json:"artist"`
|
||||
Album string `json:"album"`
|
||||
SpotifyUrl string `json:"spotifyurl"`
|
||||
BandcampUrl string `json:"bandcampurl"`
|
||||
}
|
||||
|
||||
func newUrlBandcamp(auteur, album, spo, band string) UrlBandcamp {
|
||||
return UrlBandcamp{Artiste: auteur, Album: album, SpotifyUrl: spo, BandcampUrl: band}
|
||||
}
|
||||
|
||||
type RespBandcamp struct {
|
||||
Done int `json:"done"`
|
||||
Todo int `json:"todo"`
|
||||
Urls []UrlBandcamp `json:"urls"`
|
||||
}
|
||||
|
||||
func (rp *RespBandcamp) Add(tmp UrlBandcamp) []UrlBandcamp {
|
||||
rp.Urls = append(rp.Urls, tmp)
|
||||
return rp.Urls
|
||||
}
|
||||
|
||||
type SpotifyPlaylist struct {
|
||||
Href string `json:"href"`
|
||||
Items []struct {
|
||||
|
|
Loading…
Reference in a new issue