/
request.go
78 lines (63 loc) · 1.7 KB
/
request.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package upload
import (
"github.com/jmatsu/dpg/util"
"gopkg.in/guregu/null.v3"
"io"
"os"
"strconv"
"strings"
)
type Request struct {
AppFilePath string
AppVisible bool
EnableNotification bool
ShortMessage null.String
DistributionKey null.String
DistributionName null.String
ReleaseNote null.String
}
func boolToVisibility(b bool) string {
if b {
return "public"
} else {
return "private"
}
}
type Key string
const (
keyFile Key = "file"
keyShortMessage Key = "message"
keyDistributionKey Key = "distribution_key"
keyDistributionName Key = "distribution_name"
keyReleaseNote Key = "release_note"
keyNotEnableNotification Key = "disable_notify"
keyVisibility Key = "visibility"
)
func (req Request) IoReaderMap() (*map[string]io.Reader, error) {
fd, err := os.Open(req.AppFilePath)
if err != nil {
return nil, err
}
parts := map[Key]io.Reader{
keyFile: fd,
keyVisibility: strings.NewReader(boolToVisibility(req.AppVisible)),
keyNotEnableNotification: strings.NewReader(strconv.FormatBool(!req.EnableNotification)), // inverse!
}
if message := req.ShortMessage; message.Valid {
parts[keyShortMessage] = strings.NewReader(message.String)
}
if key := req.DistributionKey; key.Valid {
parts[keyDistributionKey] = strings.NewReader(key.String)
}
if name := req.DistributionName; name.Valid {
parts[keyDistributionName] = strings.NewReader(name.String)
}
if note := req.ReleaseNote; note.Valid {
parts[keyReleaseNote] = strings.NewReader(note.String)
}
out, err := util.StringifyKeysOfReaderMap(parts)
if err != nil {
return nil, err
}
return out, nil
}