marshalJSON - Provides Marshaled JSON in bytes.
()
| 417 | |
| 418 | // marshalJSON - Provides Marshaled JSON in bytes. |
| 419 | func (p PostPolicy) marshalJSON() []byte { |
| 420 | expirationStr := `"expiration":"` + p.expiration.UTC().Format(expirationDateFormat) + `"` |
| 421 | var conditionsStr string |
| 422 | conditions := []string{} |
| 423 | for _, po := range p.conditions { |
| 424 | conditions = append(conditions, fmt.Sprintf("[\"%s\",\"%s\",\"%s\"]", po.matchType, po.condition, po.value)) |
| 425 | } |
| 426 | if p.contentLengthRange.min != 0 || p.contentLengthRange.max != 0 { |
| 427 | conditions = append(conditions, fmt.Sprintf("[\"content-length-range\", %d, %d]", |
| 428 | p.contentLengthRange.min, p.contentLengthRange.max)) |
| 429 | } |
| 430 | if len(conditions) > 0 { |
| 431 | conditionsStr = `"conditions":[` + strings.Join(conditions, ",") + "]" |
| 432 | } |
| 433 | retStr := "{" |
| 434 | retStr = retStr + expirationStr + "," |
| 435 | retStr += conditionsStr |
| 436 | retStr += "}" |
| 437 | return []byte(retStr) |
| 438 | } |
| 439 | |
| 440 | // base64 - Produces base64 of PostPolicy's Marshaled json. |
| 441 | func (p PostPolicy) base64() string { |