Skip to content

Commit

Permalink
fix: scw.File unmarshal
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Cyvoct <pcyvoct@scaleway.com>
  • Loading branch information
Sh4d1 committed Oct 3, 2019
1 parent 1e1dbdb commit 9cf8347
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scw/custom_types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package scw

import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"strings"
"time"

"github.com/scaleway/scaleway-sdk-go/internal/errors"
Expand Down Expand Up @@ -37,6 +39,30 @@ type File struct {
Content io.Reader `json:"content"`
}

func (f *File) UnmarshalJSON(b []byte) error {
var tmpFile struct {
Name string `json:"name"`
ContentType string `json:"content_type"`
Content []byte `json:"content"`
}

err := json.Unmarshal(b, &tmpFile)
if err != nil {
return err
}

f.Name = tmpFile.Name
f.ContentType = tmpFile.ContentType

content, err := base64.StdEncoding.DecodeString(string(tmpFile.Content))
if err != nil {
return err
}
f.Content = strings.NewReader(string(content))

return nil
}

// Money represents an amount of money with its currency type.
type Money struct {
// CurrencyCode is the 3-letter currency code defined in ISO 4217.
Expand Down

0 comments on commit 9cf8347

Please sign in to comment.