Remove unused api and realtime
This commit is contained in:
@@ -1,75 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
// import (
|
||||
// "bytes"
|
||||
// "context"
|
||||
// "encoding/json"
|
||||
// "fmt"
|
||||
// "io"
|
||||
// "log"
|
||||
// "net/http"
|
||||
// )
|
||||
|
||||
type APIError struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data APIErrorData `json:"data"`
|
||||
}
|
||||
// type APIError struct {
|
||||
// Code int `json:"code"`
|
||||
// Message string `json:"message"`
|
||||
// Data APIErrorData `json:"data"`
|
||||
// }
|
||||
|
||||
type APIErrorData struct {
|
||||
Link APIErrorLink `json:"link"`
|
||||
}
|
||||
// type APIErrorData struct {
|
||||
// Link APIErrorLink `json:"link"`
|
||||
// }
|
||||
|
||||
type APIErrorLink struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
// type APIErrorLink struct {
|
||||
// Code string `json:"code"`
|
||||
// Message string `json:"message"`
|
||||
// }
|
||||
|
||||
func SetDownloaded(item PBEvent) (err error) {
|
||||
req, err := http.NewRequestWithContext(context.Background(), "PATCH", FULL_URL+"/"+item.Record.Id, nil)
|
||||
if err != nil {
|
||||
log.Printf("Error creating PATCH request: %++v", err)
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
// func SetDownloaded(item PBEvent) (err error) {
|
||||
// req, err := http.NewRequestWithContext(context.Background(), "PATCH", FULL_URL+"/"+item.Record.Id, nil)
|
||||
// if err != nil {
|
||||
// log.Printf("Error creating PATCH request: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
partialItem := new(PBEvent)
|
||||
partialItem.Record = item.Record
|
||||
partialItem.Record.Downloaded = true
|
||||
// partialItem := new(PBEvent)
|
||||
// partialItem.Record = item.Record
|
||||
// partialItem.Record.Downloaded = true
|
||||
|
||||
body, err := json.Marshal(partialItem.Record)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling subscription body: %++v", err)
|
||||
return err
|
||||
}
|
||||
req.Body = io.NopCloser(bytes.NewReader(body))
|
||||
// body, err := json.Marshal(partialItem.Record)
|
||||
// if err != nil {
|
||||
// log.Printf("Error marshalling subscription body: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// req.Body = io.NopCloser(bytes.NewReader(body))
|
||||
|
||||
client := http.Client{}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Printf("Error sending PATCH request: %++v", err)
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
// client := http.Client{}
|
||||
// res, err := client.Do(req)
|
||||
// if err != nil {
|
||||
// log.Printf("Error sending PATCH request: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
log.Printf("Non-OK HTTP status: %d", res.StatusCode)
|
||||
// if res.StatusCode != http.StatusOK {
|
||||
// log.Printf("Non-OK HTTP status: %d", res.StatusCode)
|
||||
|
||||
body, err = io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Printf("Error reading response body: %++v", err)
|
||||
return err
|
||||
}
|
||||
var data APIError
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshaling JSON: %++v", err)
|
||||
return err
|
||||
}
|
||||
// body, err = io.ReadAll(res.Body)
|
||||
// if err != nil {
|
||||
// log.Printf("Error reading response body: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
// var data APIError
|
||||
// err = json.Unmarshal(body, &data)
|
||||
// if err != nil {
|
||||
// log.Printf("Error unmarshaling JSON: %++v", err)
|
||||
// return err
|
||||
// }
|
||||
|
||||
log.Printf("API error: %++v", data)
|
||||
return fmt.Errorf("Non-OK HTTP status, err: %++v", data)
|
||||
}
|
||||
// log.Printf("API error: %++v", data)
|
||||
// return fmt.Errorf("Non-OK HTTP status, err: %++v", data)
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
// return nil
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user