@@ -138,6 +138,12 @@ func GetIntValue(r interface{}) int {
138138 return int (r .(int32 ))
139139 case float64 :
140140 return int (r .(float64 ))
141+ case string :
142+ val , err := strconv .Atoi (r .(string ))
143+ if err != nil {
144+ return 0
145+ }
146+ return val
141147 }
142148 return 0
143149}
@@ -155,55 +161,55 @@ func GetInt64Value(records map[string]interface{}, key string) int64 {
155161}
156162
157163func GetExpirationNum (val interface {}) int32 {
158- now := int32 (time .Now ().Unix ())
159- num := int32 (0 )
160- switch val .(type ) {
161- case nil :
162- return 0
163- case int :
164- num = int32 (val .(int ))
165- case int32 :
166- num = val .(int32 )
167- case int64 :
168- num = int32 (val .(int64 ))
169- case float64 :
170- num = int32 (val .(float64 ))
171- case string :
172- expiration := val .(string )
173- if len (expiration ) == 0 {
174- return 0
175- }
176- match := regexExpiration .FindStringSubmatch (expiration )
177- // expiration format: 10d, 10h, 10m, 10s
178- if len (match ) == 2 {
179- num = Atoi (match [1 ])
180- } else {
181- if len (match ) != 3 {
182- log .Printf ("Failed to parse expiration value: %s" , expiration )
183- return 0
184- }
185- numStr := match [1 ]
186- format := match [2 ]
187- if len (format ) == 0 {
188- num = Atoi (numStr )
189- } else {
190- switch format {
191- case "d" : // day
192- num = (Atoi (numStr ) * 24 * 3600 )
193- case "h" : // hour
194- num = (Atoi (numStr ) * 3600 )
195- case "m" : // month
196- num = (Atoi (numStr ) * 24 * 31 * 3600 )
197- case "s" :
198- num = (Atoi (numStr ))
199- }
200- }
201- }
202- }
203- if num > now {
204- return num - now
205- }
206- return num
164+ now := int32 (time .Now ().Unix ())
165+ num := int32 (0 )
166+ switch val .(type ) {
167+ case nil :
168+ return 0
169+ case int :
170+ num = int32 (val .(int ))
171+ case int32 :
172+ num = val .(int32 )
173+ case int64 :
174+ num = int32 (val .(int64 ))
175+ case float64 :
176+ num = int32 (val .(float64 ))
177+ case string :
178+ expiration := val .(string )
179+ if len (expiration ) == 0 {
180+ return 0
181+ }
182+ match := regexExpiration .FindStringSubmatch (expiration )
183+ // expiration format: 10d, 10h, 10m, 10s
184+ if len (match ) == 2 {
185+ num = Atoi (match [1 ])
186+ } else {
187+ if len (match ) != 3 {
188+ log .Printf ("Failed to parse expiration value: %s" , expiration )
189+ return 0
190+ }
191+ numStr := match [1 ]
192+ format := match [2 ]
193+ if len (format ) == 0 {
194+ num = Atoi (numStr )
195+ } else {
196+ switch format {
197+ case "d" : // day
198+ num = (Atoi (numStr ) * 24 * 3600 )
199+ case "h" : // hour
200+ num = (Atoi (numStr ) * 3600 )
201+ case "m" : // month
202+ num = (Atoi (numStr ) * 24 * 31 * 3600 )
203+ case "s" :
204+ num = (Atoi (numStr ))
205+ }
206+ }
207+ }
208+ }
209+ if num > now {
210+ return num - now
211+ }
212+ return num
207213}
208214
209215func GetArgEnvFileVariable (vname string , masterKeyPtr * string ) string {
0 commit comments