GofileScrapper/api/content.go

32 lines
694 B
Go
Raw Permalink Normal View History

2024-03-19 16:20:55 +00:00
package api
import (
"GofileScrapper/misc"
"GofileScrapper/structs"
"bytes"
"encoding/json"
"fmt"
)
func GetContent(guest structs.Guest, id string) (structs.Content, error) {
body, err := misc.Fetch(
"GET",
2024-03-20 09:10:20 +00:00
misc.ApiUrl+"/contents/"+id+"?wt=4fd6sg89d7s6",
2024-03-19 16:20:55 +00:00
bytes.NewBuffer([]byte(`{}`)),
[]misc.HeaderType{
{Key: "Authorization", Value: fmt.Sprintf("Bearer %s", guest.Data.Token)},
},
)
if err != nil {
return structs.Content{}, fmt.Errorf("error reading response body: %v", err)
}
var content structs.Content
err = json.Unmarshal(body, &content)
if err != nil {
return structs.Content{}, fmt.Errorf("error unmarshalling JSON: %v", err)
}
return content, nil
}