-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
55 lines (44 loc) · 1.08 KB
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package pinata
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
)
type PinataUpdateMeta struct {
IpfsPinHash string `json:"ipfsPinHash"`
Name string `json:"name"`
KeyValues *map[string]string `json:"keyvalues"`
}
func (pinata *Pinata) updateMetadata(cid string, name string, keyValues *map[string]string) ([]byte, error) {
method := "PUT"
metaData := &PinataUpdateMeta{
IpfsPinHash: cid,
Name: name,
KeyValues: keyValues,
}
metaDataString, err := json.MarshalIndent(metaData, "", "\t")
if err != nil {
return nil, err
}
payload := strings.NewReader(string(metaDataString))
client := &http.Client{}
req, err := http.NewRequest(method, string(UPDATEMETA), payload)
if err != nil {
return nil, err
}
req.Header.Add("Authorization", "Bearer "+pinata.authentication)
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return nil, err
}
return body, nil
}