Skip to content

Commit eda816a

Browse files
committed
refactor: mime/multipart: update Part field names for consistency
1 parent 4dd5118 commit eda816a

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

mime/multipartutil/multipart_simple.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (ms MultipartSimple) Part() (Part, error) {
3939
return Part{}, err
4040
} else {
4141
return Part{
42-
Type: PartTypeRaw,
43-
ContentType: ct,
44-
Base64Encode: false,
45-
RawBody: []byte(body),
42+
Type: PartTypeRaw,
43+
ContentType: ct,
44+
BodyEncodeBase64: false,
45+
BodyDataRaw: []byte(body),
4646
}, nil
4747
}
4848
}

mime/multipartutil/multipart_simple_alternative.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ func NewPartAlternativeOrNot(text, html []byte) (Part, error) {
1010
return mps.Part()
1111
} else if len(html) > 0 {
1212
return Part{
13-
Type: PartTypeRaw,
14-
ContentType: httputilmore.ContentTypeTextHTMLUtf8,
15-
Base64Encode: false,
16-
RawBody: html,
13+
Type: PartTypeRaw,
14+
ContentType: httputilmore.ContentTypeTextHTMLUtf8,
15+
BodyEncodeBase64: false,
16+
BodyDataRaw: html,
1717
}, nil
1818
} else {
1919
return Part{
20-
Type: PartTypeRaw,
21-
ContentType: httputilmore.ContentTypeTextPlainUtf8,
22-
Base64Encode: false,
23-
RawBody: text,
20+
Type: PartTypeRaw,
21+
ContentType: httputilmore.ContentTypeTextPlainUtf8,
22+
BodyEncodeBase64: false,
23+
BodyDataRaw: text,
2424
}, nil
2525
}
2626
}
@@ -30,15 +30,15 @@ func NewMultipartSimpleAlternative(text, html []byte) MultipartSimple {
3030
ContentType: httputilmore.ContentTypeMultipartAlternative,
3131
Parts: []Part{
3232
{
33-
Type: PartTypeRaw,
34-
ContentType: httputilmore.ContentTypeTextPlain,
35-
Base64Encode: false,
36-
RawBody: text,
33+
Type: PartTypeRaw,
34+
ContentType: httputilmore.ContentTypeTextPlain,
35+
BodyEncodeBase64: false,
36+
BodyDataRaw: text,
3737
}, {
38-
Type: PartTypeRaw,
39-
ContentType: httputilmore.ContentTypeTextHTMLUtf8,
40-
Base64Encode: false,
41-
RawBody: html,
38+
Type: PartTypeRaw,
39+
ContentType: httputilmore.ContentTypeTextHTMLUtf8,
40+
BodyEncodeBase64: false,
41+
BodyDataRaw: html,
4242
},
4343
},
4444
}

mime/multipartutil/part.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ type Part struct {
2727
Name string
2828
ContentType string
2929
ContentDisposition string // short
30-
Base64Encode bool
31-
Filepath string
32-
JSONBody any
33-
RawBody []byte
34-
RawHeader textproto.MIMEHeader
30+
HeaderRaw textproto.MIMEHeader
31+
BodyDataFilepath string
32+
BodyDataJSON any
33+
BodyDataRaw []byte
34+
BodyEncodeBase64 bool
3535
}
3636

3737
// HeaderBodyFilepath sets Content-Disposition and Content-Type.
@@ -42,25 +42,25 @@ func (p Part) HeaderBodyFilepath() (textproto.MIMEHeader, []byte, error) {
4242
header.Add(hum.HeaderContentDisposition, cd)
4343
}
4444

45-
_, filename := filepath.Split(p.Filepath)
45+
_, filename := filepath.Split(p.BodyDataFilepath)
4646
filename = strings.TrimSpace(filename)
47-
mimeType := mime.TypeByExtension(filepath.Ext(p.Filepath))
47+
mimeType := mime.TypeByExtension(filepath.Ext(p.BodyDataFilepath))
4848
if len(mimeType) > 0 {
4949
header.Add(hum.HeaderContentType, mimeType)
5050
}
5151

52-
for k, vals := range p.RawHeader {
52+
for k, vals := range p.HeaderRaw {
5353
for _, v := range vals {
5454
header.Add(k, v)
5555
}
5656
}
5757

58-
body, err := os.ReadFile(p.Filepath)
58+
body, err := os.ReadFile(p.BodyDataFilepath)
5959
if err != nil {
6060
return header, []byte{}, err
6161
}
6262

63-
if p.Base64Encode {
63+
if p.BodyEncodeBase64 {
6464
header.Add(hum.HeaderContentTransferEncoding, "base64")
6565
body = []byte(base64.StdEncoding.EncodeToString(body))
6666
}
@@ -77,9 +77,9 @@ func (p Part) FilepathToRaw() (Part, error) {
7777
return Part{}, err
7878
}
7979
return Part{
80-
Type: PartTypeRaw,
81-
RawHeader: header,
82-
RawBody: body,
80+
Type: PartTypeRaw,
81+
HeaderRaw: header,
82+
BodyDataRaw: body,
8383
}, nil
8484
}
8585

@@ -90,7 +90,7 @@ func (p *Part) ContentDispositionHeader() string {
9090
if name != "" {
9191
params["name"] = name
9292
}
93-
_, filename := filepath.Split(p.Filepath)
93+
_, filename := filepath.Split(p.BodyDataFilepath)
9494
if filename = strings.TrimSpace(filename); filename != "" {
9595
params["filename"] = filename
9696
}
@@ -108,12 +108,12 @@ func (p *Part) HeaderBodyJSON() (textproto.MIMEHeader, []byte, error) {
108108

109109
header.Add(hum.HeaderContentType, hum.ContentTypeAppJSONUtf8)
110110

111-
body, err := json.Marshal(p.JSONBody)
111+
body, err := json.Marshal(p.BodyDataJSON)
112112
if err != nil {
113113
return header, []byte{}, err
114114
}
115115

116-
if p.Base64Encode {
116+
if p.BodyEncodeBase64 {
117117
header.Add(hum.HeaderContentTransferEncoding, "base64")
118118
body = []byte(base64.StdEncoding.EncodeToString(body))
119119
}
@@ -126,12 +126,12 @@ func (p Part) HeaderBodyRaw() (textproto.MIMEHeader, []byte, error) {
126126
if strings.TrimSpace(p.ContentType) != "" {
127127
header.Add(hum.HeaderContentType, p.ContentType)
128128
}
129-
body := p.RawBody
130-
if p.Base64Encode {
129+
body := p.BodyDataRaw
130+
if p.BodyEncodeBase64 {
131131
header.Add(hum.HeaderContentTransferEncoding, "base64")
132132
body = []byte(base64.StdEncoding.EncodeToString(body))
133133
}
134-
for k, vals := range p.RawHeader {
134+
for k, vals := range p.HeaderRaw {
135135
for _, v := range vals {
136136
header.Add(k, v)
137137
}

0 commit comments

Comments
 (0)