commit b66ec6a10291e51d525e2cf6a8a6fda11d23effe Author: David Majdandžić Date: Sun Jun 16 22:30:00 2024 +0200 Initial commit diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1ae2eee --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module main + +go 1.22.4 + +require github.com/tmaxmax/go-sse v0.8.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0cb5fa6 --- /dev/null +++ b/go.sum @@ -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= diff --git a/main.go b/main.go new file mode 100644 index 0000000..3d22d77 --- /dev/null +++ b/main.go @@ -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) +}