Forked from mcastilho/gist:0cad4ff082d07bb0f72b48c449390cb7
Created
September 1, 2017 18:32
-
-
Save chsjiang/c4e077e65288406b5c4f4e3fbc9069e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PayloadCollection struct { | |
WindowsVersion string `json:"version"` | |
Token string `json:"token"` | |
Payloads []Payload `json:"data"` | |
} | |
type Payload struct { | |
// [redacted] | |
} | |
func (p *Payload) UploadToS3() error { | |
// the storageFolder method ensures that there are no name collision in | |
// case we get same timestamp in the key name | |
storage_path := fmt.Sprintf("%v/%v", p.storageFolder, time.Now().UnixNano()) | |
bucket := S3Bucket | |
b := new(bytes.Buffer) | |
encodeErr := json.NewEncoder(b).Encode(payload) | |
if encodeErr != nil { | |
return encodeErr | |
} | |
// Everything we post to the S3 bucket should be marked 'private' | |
var acl = s3.Private | |
var contentType = "application/octet-stream" | |
return bucket.PutReader(storage_path, b, int64(b.Len()), contentType, acl, s3.Options{}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment