Skip to content

Commit

Permalink
Fixed disable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wesuuu committed Nov 15, 2021
1 parent 8d02e34 commit 6992448
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type CookieResponse struct {
Disable bool
}

func GetCookieResponse(cookie Cookie, timeNow time.Time, successCookieType bool) (CookieResponse, error) {
func GetCookieResponse(cookie Cookie, timeNow time.Time, successCookieType bool, disable bool) (CookieResponse, error) {

hours := strings.TrimSuffix(cookie.Expiration, "h")
expiryHours, err := strconv.Atoi(hours)
Expand All @@ -42,6 +42,7 @@ func GetCookieResponse(cookie Cookie, timeNow time.Time, successCookieType bool)
Expiration: exp,
AllCookies: allCookies,
CanaryPercent: cookie.CanaryPercent,
Disable: disable,
}

if successCookieType {
Expand Down Expand Up @@ -74,9 +75,9 @@ func GetCanaryCookie(w http.ResponseWriter, req *http.Request) {
// generate the cookie response
var cookieResponse CookieResponse
if randNum < app.CookieInfo.CanaryPercent {
cookieResponse, err = GetCookieResponse(app.CookieInfo, timeNow, true)
cookieResponse, err = GetCookieResponse(app.CookieInfo, timeNow, true, app.Disable)
} else {
cookieResponse, err = GetCookieResponse(app.CookieInfo, timeNow, false)
cookieResponse, err = GetCookieResponse(app.CookieInfo, timeNow, false, app.Disable)
}
if err != nil {
respondWithError(w, http.StatusInternalServerError, "Could not get canary cookie!")
Expand Down Expand Up @@ -125,9 +126,9 @@ func GetCookieByType(w http.ResponseWriter, req *http.Request) {
if appName == app.Name {
var cookieResponse CookieResponse
if cookieType == "success" {
cookieResponse, err = GetCookieResponse(app.CookieInfo, time.Now(), true)
cookieResponse, err = GetCookieResponse(app.CookieInfo, time.Now(), true, app.Disable)
} else {
cookieResponse, err = GetCookieResponse(app.CookieInfo, time.Now(), false)
cookieResponse, err = GetCookieResponse(app.CookieInfo, time.Now(), false, app.Disable)
}
if err != nil {
log.Println(err)
Expand Down

0 comments on commit 6992448

Please sign in to comment.