chenwanli 6 years ago
parent
commit
fd27ed7755
  1. 38
      weed/storage/volume_ttl.go

38
weed/storage/volume_ttl.go

@ -16,8 +16,8 @@ const (
)
type TTL struct {
count byte
unit byte
Count byte
Unit byte
}
var EMPTY_TTL = &TTL{}
@ -43,12 +43,12 @@ func ReadTTL(ttlString string) (*TTL, error) {
}
count, err := strconv.Atoi(string(countBytes))
unit := toStoredByte(unitByte)
return &TTL{count: byte(count), unit: unit}, err
return &TTL{Count: byte(count), Unit: unit}, err
}
// read stored bytes to a ttl
func LoadTTLFromBytes(input []byte) (t *TTL) {
return &TTL{count: input[0], unit: input[1]}
return &TTL{Count: input[0], Unit: input[1]}
}
// read stored bytes to a ttl
@ -61,25 +61,25 @@ func LoadTTLFromUint32(ttl uint32) (t *TTL) {
// save stored bytes to an output with 2 bytes
func (t *TTL) ToBytes(output []byte) {
output[0] = t.count
output[1] = t.unit
output[0] = t.Count
output[1] = t.Unit
}
func (t *TTL) ToUint32() (output uint32) {
output = uint32(t.count) << 8
output += uint32(t.unit)
output = uint32(t.Count) << 8
output += uint32(t.Unit)
return output
}
func (t *TTL) String() string {
if t == nil || t.count == 0 {
if t == nil || t.Count == 0 {
return ""
}
if t.unit == Empty {
if t.Unit == Empty {
return ""
}
countString := strconv.Itoa(int(t.count))
switch t.unit {
countString := strconv.Itoa(int(t.Count))
switch t.Unit {
case Minute:
return countString + "m"
case Hour:
@ -115,21 +115,21 @@ func toStoredByte(readableUnitByte byte) byte {
}
func (t TTL) Minutes() uint32 {
switch t.unit {
switch t.Unit {
case Empty:
return 0
case Minute:
return uint32(t.count)
return uint32(t.Count)
case Hour:
return uint32(t.count) * 60
return uint32(t.Count) * 60
case Day:
return uint32(t.count) * 60 * 24
return uint32(t.Count) * 60 * 24
case Week:
return uint32(t.count) * 60 * 24 * 7
return uint32(t.Count) * 60 * 24 * 7
case Month:
return uint32(t.count) * 60 * 24 * 31
return uint32(t.Count) * 60 * 24 * 31
case Year:
return uint32(t.count) * 60 * 24 * 365
return uint32(t.Count) * 60 * 24 * 365
}
return 0
}
Loading…
Cancel
Save