Skip to content

Commit b8ef0ae

Browse files
committed
fix: update validity check condition
1 parent 89365f7 commit b8ef0ae

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

util/billing.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
var TimeValidity int64
17+
var MAX_ALLOWED_TIME int64 = 24 // in hrs
1718

1819
type ArcUsage struct {
1920
ArcID string `json:"arc_id"`
@@ -42,11 +43,13 @@ const (
4243
// Middleware function, which will be called for each request
4344
func BillingMiddleware(next http.Handler) http.Handler {
4445
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
45-
// Valid plan
46-
if TimeValidity > 0 {
47-
// Check if remaining time is less than 24 hrs
48-
if TimeValidity <= 3600*24 {
49-
// Print warning message if remaining time is less than 24 hrs
46+
if TimeValidity > 0 { // Valid plan
47+
next.ServeHTTP(w, r)
48+
} else if -(TimeValidity) <= 3600*MAX_ALLOWED_TIME {
49+
// Print warning message if remaining time is less than max allowed time
50+
if TimeValidity == 0 { // Rare, but it can happen when tier has been just expired
51+
log.Println("warning: payment required. arc will start sending out error messages in some time")
52+
} else {
5053
log.Println("warning: payment required. arc will start sending out error messages in next", TimeValidity/3600, "hours")
5154
}
5255
next.ServeHTTP(w, r)

0 commit comments

Comments
 (0)