Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. if ok, matchingTests := abStyleTests.HasMatchingPathNameTest(r, multilingual, language); ok {
  2. var testContext string
  3. for _, currentTest := range matchingTests {
  4. var abtestCookie ab_test.AbTestCookie
  5. cookie, err := ab_test.GetCookieValue(r, currentTest.TestName, ab_test.STYLE_TEST)
  6. if err == nil {
  7. abtestCookie, err = ab_test.ParseCookieValue(cookie)
  8. }
  9. if err != nil || abtestCookie.Index < 0 {
  10. if currentTest.VariantsCount > 0 {
  11. idx := rand.Intn(currentTest.VariantsCount)
  12. testContext = concatenateStyles(testContext, currentTest.TestName, currentTest.Variants[idx].Variant, currentTest.Variants[idx].Name, idx)
  13. cookie, err := ab_test.CreateCookieValue(currentTest.Variants[idx].Name, idx)
  14. if err != nil {
  15. log.Infof(ctx, "Could not create A/B tests cookie: %s", err.Error())
  16. next.ServeHTTP(w, r)
  17. return
  18. }
  19. ab_test.SetCookieValue(w, r.Host, currentTest.TestName, cookie, ab_test.STYLE_TEST)
  20. }
  21. } else {
  22. idx := abtestCookie.Index
  23. if currentTest.VariantsCount >= idx {
  24. testContext = concatenateStyles(testContext, currentTest.TestName, currentTest.Variants[idx].Variant, currentTest.Variants[idx].Name, idx)
  25. }
  26. }
  27. }
  28.  
  29. ctx = context.WithValue(ctx, "AbStyleTest", testContext)
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement