Initial commit

This commit is contained in:
2024-06-16 22:30:00 +02:00
commit b66ec6a102
3 changed files with 65 additions and 0 deletions

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module main
go 1.22.4
require github.com/tmaxmax/go-sse v0.8.0 // indirect

2
go.sum Normal file
View File

@@ -0,0 +1,2 @@
github.com/tmaxmax/go-sse v0.8.0 h1:pPpTgyyi1r7vG2o6icebnpGEh3ebcnBXqDWkb7aTofs=
github.com/tmaxmax/go-sse v0.8.0/go.mod h1:HLoxqxdH+7oSUItjtnpxjzJedfr/+Rrm/dNWBcTxJFM=

58
main.go Normal file
View File

@@ -0,0 +1,58 @@
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)
}