forked from rclone/go-proton-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader_types.go
More file actions
47 lines (34 loc) · 696 Bytes
/
Copy pathheader_types.go
File metadata and controls
47 lines (34 loc) · 696 Bytes
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
package proton
import (
"encoding/json"
"errors"
)
var ErrBadHeader = errors.New("bad header")
type Headers map[string][]string
func (h *Headers) UnmarshalJSON(b []byte) error {
type rawHeaders map[string]any
raw := make(rawHeaders)
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
header := make(Headers)
for key, val := range raw {
switch val := val.(type) {
case string:
header[key] = []string{val}
case []any:
for _, val := range val {
switch val := val.(type) {
case string:
header[key] = append(header[key], val)
default:
return ErrBadHeader
}
}
default:
return ErrBadHeader
}
}
*h = header
return nil
}