Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ok, matchingTests := abStyleTests.HasMatchingPathNameTest(r, multilingual, language); ok {
- var testContext string
- for _, currentTest := range matchingTests {
- var abtestCookie ab_test.AbTestCookie
- cookie, err := ab_test.GetCookieValue(r, currentTest.TestName, ab_test.STYLE_TEST)
- if err == nil {
- abtestCookie, err = ab_test.ParseCookieValue(cookie)
- }
- if err != nil || abtestCookie.Index < 0 {
- if currentTest.VariantsCount > 0 {
- idx := rand.Intn(currentTest.VariantsCount)
- testContext = concatenateStyles(testContext, currentTest.TestName, currentTest.Variants[idx].Variant, currentTest.Variants[idx].Name, idx)
- cookie, err := ab_test.CreateCookieValue(currentTest.Variants[idx].Name, idx)
- if err != nil {
- log.Infof(ctx, "Could not create A/B tests cookie: %s", err.Error())
- next.ServeHTTP(w, r)
- return
- }
- ab_test.SetCookieValue(w, r.Host, currentTest.TestName, cookie, ab_test.STYLE_TEST)
- }
- } else {
- idx := abtestCookie.Index
- if currentTest.VariantsCount >= idx {
- testContext = concatenateStyles(testContext, currentTest.TestName, currentTest.Variants[idx].Variant, currentTest.Variants[idx].Name, idx)
- }
- }
- }
- ctx = context.WithValue(ctx, "AbStyleTest", testContext)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement