59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type Response struct {
|
|
Page int `json:"page"`
|
|
PerPage int `json:"perPage"`
|
|
TotalItems int `json:"totalItems"`
|
|
TotalPages int `json:"totalPages"`
|
|
Items []Item `json:"items"`
|
|
}
|
|
|
|
type Item struct {
|
|
CollectionId string `json:"collectionId"`
|
|
CollectionName string `json:"collectionName"`
|
|
Created string `json:"created"`
|
|
Downloaded bool `json:"downloaded"`
|
|
Id string `json:"id"`
|
|
Link string `json:"link"`
|
|
Updated string `json:"updated"`
|
|
}
|
|
|
|
const POCKETBASE_URL = `https://pocketbase-scratch.site.quack-lab.dev/api/collections`
|
|
const COLLECTION_NAME = "youtubedownload"
|
|
const FULL_URL = POCKETBASE_URL + "/" + COLLECTION_NAME + "/records"
|
|
|
|
func main() {
|
|
log.SetFlags(log.Lmicroseconds)
|
|
log.Println(FULL_URL)
|
|
|
|
res, err := http.Get(FULL_URL)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer res.Body.Close()
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
log.Println("Error reading response body:", err)
|
|
return
|
|
}
|
|
if res.StatusCode != http.StatusOK {
|
|
log.Printf("Non-OK HTTP status: %d\nResponse body: %s\n", res.StatusCode, body)
|
|
return
|
|
}
|
|
|
|
var data Response
|
|
err = json.Unmarshal(body, &data)
|
|
if err != nil {
|
|
log.Println("Error unmarshaling JSON:", err)
|
|
return
|
|
}
|
|
log.Printf("Data: %+v\n", data)
|
|
}
|