GofileScrapper/api/content.go

32 lines
694 B
Go

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",
misc.ApiUrl+"/contents/"+id+"?wt=4fd6sg89d7s6",
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
}