time.go (849B)
1 package v4 2 3 import "time" 4 5 // SigningTime provides a wrapper around a time.Time which provides cached values for SigV4 signing. 6 type SigningTime struct { 7 time.Time 8 timeFormat string 9 shortTimeFormat string 10 } 11 12 // NewSigningTime creates a new SigningTime given a time.Time 13 func NewSigningTime(t time.Time) SigningTime { 14 return SigningTime{ 15 Time: t, 16 } 17 } 18 19 // TimeFormat provides a time formatted in the X-Amz-Date format. 20 func (m *SigningTime) TimeFormat() string { 21 return m.format(&m.timeFormat, TimeFormat) 22 } 23 24 // ShortTimeFormat provides a time formatted of 20060102. 25 func (m *SigningTime) ShortTimeFormat() string { 26 return m.format(&m.shortTimeFormat, ShortTimeFormat) 27 } 28 29 func (m *SigningTime) format(target *string, format string) string { 30 if len(*target) > 0 { 31 return *target 32 } 33 v := m.Time.Format(format) 34 *target = v 35 return v 36 }