Skip to content

Commit 47f74fd

Browse files
committed
add DecodeBytesInto
1 parent 86c6b5f commit 47f74fd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

form/bytes.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010

1111
type Bytes []byte
1212

13+
func (x Bytes) Bytes() []byte {
14+
return []byte(x)
15+
}
16+
1317
func (x Bytes) MarshalJSON() ([]byte, error) {
1418
return json.Marshal(EncodeBytesToString(x))
1519
}

form/form.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func DecodeBytes[F Form](ctx context.Context, data []byte) (form F, err error) {
5555
return form, err
5656
}
5757

58+
func DecodeBytesInto(ctx context.Context, data []byte, into Form) error {
59+
return json.Unmarshal(data, into)
60+
}
61+
5862
func EncodeToFile[F Form](ctx context.Context, fs billy.Filesystem, path string, form F) error {
5963
file, err := fs.Create(path)
6064
if err != nil {

0 commit comments

Comments
 (0)