1 changed files with 64 additions and 7 deletions
-
71app/main.go
@ -1,15 +1,72 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"log" |
|||
"net/http" |
|||
"encoding/json" |
|||
"fmt" |
|||
"io/ioutil" |
|||
"log" |
|||
"net/http" |
|||
"time" |
|||
) |
|||
|
|||
|
|||
type Podcasts struct { |
|||
URL string `json:"url"` |
|||
Title string `json:"title"` |
|||
Date time.Time `json:"date"` |
|||
Categories []string `json:"categories"` |
|||
Image string `json:"image,omitempty"` |
|||
FileName string `json:"file_name,omitempty"` |
|||
Body string `json:"body"` |
|||
ShowNotes string `json:"show_notes,omitempty"` |
|||
AudioUrl string `json:"audio_url"` |
|||
TimeLabels []TimeLabels |
|||
ShowNum int `json:"show_num,omitempty"` |
|||
} |
|||
|
|||
type TimeLabels struct { |
|||
Topic string `json:"topic,omitempty"` |
|||
Time time.Time `json:"time,omitempty"` |
|||
Duration int `json:"duration,omitempty"` |
|||
} |
|||
|
|||
|
|||
func main() { |
|||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
|||
fmt.Fprintf(w, "Go app is worked!") |
|||
}) |
|||
var lines []string |
|||
fmt.Println(getRadioTThemes(1)) |
|||
for _, podcast := range getRadioTThemes(5) { |
|||
lines = append(lines, fmt.Sprintf("[%s](%s) %s\n %s\n\n", |
|||
podcast.Title, |
|||
podcast.URL, |
|||
podcast.Date.Format("2006-01-02"), |
|||
podcast.Body, |
|||
)) |
|||
} |
|||
|
|||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
|||
fmt.Fprintf(w, "%s", lines) |
|||
}) |
|||
|
|||
log.Fatal(http.ListenAndServe(":7070", nil)) |
|||
} |
|||
|
|||
func getRadioTThemes(numPodcasts int) []Podcasts { |
|||
var url string |
|||
url = fmt.Sprintf("https://radio-t.com/site-api/last/%d?categories=podcast", numPodcasts) |
|||
response, err := http.Get(url) |
|||
|
|||
if err != nil { |
|||
panic(err.Error()) |
|||
} |
|||
|
|||
body, err := ioutil.ReadAll(response.Body) |
|||
|
|||
if err != nil { |
|||
panic(err.Error()) |
|||
} |
|||
|
|||
var podcasts []Podcasts |
|||
json.Unmarshal(body, &podcasts) |
|||
|
|||
log.Fatal(http.ListenAndServe(":7070", nil)) |
|||
return podcasts |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue