mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-10-29 17:12:22 +00:00
review date expiration functions
This commit is contained in:
@@ -154,65 +154,53 @@ func GetInt64Value(records map[string]interface{}, key string) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetExpirationNum(val interface{}) int32 {
|
func GetExpirationNum(val interface{}) int32 {
|
||||||
now := int32(time.Now().Unix())
|
now := int32(time.Now().Unix())
|
||||||
num := int32(0)
|
num := int32(0)
|
||||||
switch val.(type) {
|
switch val.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return 0
|
return 0
|
||||||
case int:
|
case int:
|
||||||
num = int32(val.(int))
|
num = int32(val.(int))
|
||||||
if num > now {
|
case int32:
|
||||||
return num - now
|
num = val.(int32)
|
||||||
}
|
case int64:
|
||||||
return num
|
num = int32(val.(int64))
|
||||||
case int32:
|
case float64:
|
||||||
num = val.(int32)
|
num = int32(val.(float64))
|
||||||
if num > now {
|
case string:
|
||||||
return num - now
|
expiration := val.(string)
|
||||||
}
|
match := regexExpiration.FindStringSubmatch(expiration)
|
||||||
return num
|
log.Printf("match: %v", match)
|
||||||
case int64:
|
// expiration format: 10d, 10h, 10m, 10s
|
||||||
num = int32(val.(int64))
|
if len(match) == 2 {
|
||||||
if num > now {
|
num = Atoi(match[1])
|
||||||
return num - now
|
} else {
|
||||||
}
|
if len(match) != 3 {
|
||||||
return num
|
log.Printf("failed to parse expiration value: %s", expiration)
|
||||||
case float64:
|
return 0
|
||||||
num = int32(val.(float64))
|
}
|
||||||
if num > now {
|
numStr := match[1]
|
||||||
return num - now
|
format := match[2]
|
||||||
}
|
if len(format) == 0 {
|
||||||
return num
|
num = Atoi(numStr)
|
||||||
case string:
|
} else {
|
||||||
expiration := val.(string)
|
switch format {
|
||||||
match := regexExpiration.FindStringSubmatch(expiration)
|
case "d": // day
|
||||||
// expiration format: 10d, 10h, 10m, 10s
|
num = (Atoi(numStr) * 24 * 3600)
|
||||||
if len(match) == 2 {
|
case "h": // hour
|
||||||
return Atoi(match[1])
|
num = (Atoi(numStr) * 3600)
|
||||||
}
|
case "m": // month
|
||||||
if len(match) != 3 {
|
num = (Atoi(numStr) * 24 * 31 * 3600)
|
||||||
log.Printf("failed to parse expiration value: %s", expiration)
|
case "s":
|
||||||
return 0
|
num = (Atoi(numStr))
|
||||||
}
|
}
|
||||||
num2 := match[1]
|
}
|
||||||
format := match[2]
|
}
|
||||||
if len(format) == 0 {
|
}
|
||||||
return Atoi(num2)
|
if num > now {
|
||||||
}
|
return num - now
|
||||||
start := int32(0)
|
}
|
||||||
switch format {
|
return num
|
||||||
case "d": // day
|
|
||||||
start = (Atoi(num2) * 24 * 3600)
|
|
||||||
case "h": // hour
|
|
||||||
start = (Atoi(num2) * 3600)
|
|
||||||
case "m": // month
|
|
||||||
start = (Atoi(num2) * 24 * 31 * 3600)
|
|
||||||
case "s":
|
|
||||||
start = (Atoi(num2))
|
|
||||||
}
|
|
||||||
return start
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArgEnvFileVariable(vname string, masterKeyPtr *string) string {
|
func GetArgEnvFileVariable(vname string, masterKeyPtr *string) string {
|
||||||
@@ -368,33 +356,13 @@ func ParseExpiration0(expiration string) (int32, error) {
|
|||||||
return start, nil
|
return start, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseExpiration(expiration string) (int32, error) {
|
func ParseExpiration(expiration interface{}) (int32, error) {
|
||||||
match := regexExpiration.FindStringSubmatch(expiration)
|
now := int32(time.Now().Unix()) + 10
|
||||||
// expiration format: 10d, 10h, 10m, 10s
|
result := GetExpirationNum(expiration)
|
||||||
if len(match) == 2 {
|
if result == 0 {
|
||||||
return Atoi(match[1]), nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
if len(match) != 3 {
|
return result + now, nil
|
||||||
e := fmt.Sprintf("failed to parse expiration value: %s", expiration)
|
|
||||||
return 0, errors.New(e)
|
|
||||||
}
|
|
||||||
num := match[1]
|
|
||||||
format := match[2]
|
|
||||||
if len(format) == 0 {
|
|
||||||
return Atoi(num), nil
|
|
||||||
}
|
|
||||||
start := int32(time.Now().Unix())
|
|
||||||
switch format {
|
|
||||||
case "d": // day
|
|
||||||
start = start + (Atoi(num) * 24 * 3600)
|
|
||||||
case "h": // hour
|
|
||||||
start = start + (Atoi(num) * 3600)
|
|
||||||
case "m": // month
|
|
||||||
start = start + (Atoi(num) * 24 * 31 * 3600)
|
|
||||||
case "s":
|
|
||||||
start = start + (Atoi(num))
|
|
||||||
}
|
|
||||||
return start, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LockMemory() error {
|
func LockMemory() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user