Documentation ¶
Index ¶
- Variables
- func GetCollection(req *http.Request) (string, error)
- func GetIDToken(req *http.Request) (string, error)
- func GetLang(req *http.Request) (string, error)
- func GetRefreshToken(req *http.Request) (string, error)
- func GetUserAuthToken(req *http.Request) (string, error)
- func HandleABTestExit(w http.ResponseWriter, req *http.Request, o http.Handler, ...)
- func HandleCookieAndServ(w http.ResponseWriter, req *http.Request, n, o http.Handler, ...)
- func Handler(abTest bool, newHandler, oldHandler http.Handler, percentage int, ...) http.HandlerFunc
- func RemoveABTestCookieAspect(w http.ResponseWriter, req *http.Request, aspectID, domain string)
- func ServABTest(w http.ResponseWriter, req *http.Request, n, o http.Handler, ...)
- func SetABTestCookieAspect(w http.ResponseWriter, req *http.Request, aspectID, domain string, ...)
- func SetCollection(w http.ResponseWriter, value, domain string)
- func SetIDToken(w http.ResponseWriter, idToken, domain string)
- func SetLang(w http.ResponseWriter, lang, domain string)
- func SetPolicy(w http.ResponseWriter, policy Policy, domain string)
- func SetPreferenceIsSet(w http.ResponseWriter, domain string)
- func SetRefreshToken(w http.ResponseWriter, refreshToken, domain string)
- func SetUserAuthToken(w http.ResponseWriter, userAuthToken, domain string)
- type ABTestCookieAspect
- type CookieTime
- type InvalidCookieTimeString
- type Policy
- type PreferencesResponse
- type Randomiser
Constants ¶
This section is empty.
Variables ¶
var DefaultABTestRandomiser = func(percentage int) Randomiser { return func() ABTestCookieAspect { now := Now() if rand.Intn(100) < percentage { return ABTestCookieAspect{New: now.Add(time.Hour * 24), Old: now} } return ABTestCookieAspect{New: now, Old: now.Add(time.Hour * 24)} } }
var ErrABTestCookieNotFound = errors.New("a/b test cookie not found")
ErrABTestCookieNotFound is used when a/b test cookie isn't found
Functions ¶
func GetCollection ¶
GetCollection reads collection_id cookie and returns it's value
func GetIDToken ¶ added in v0.2.0
GetIDToken reads id_token cookie and returns it's value
func GetRefreshToken ¶ added in v0.2.0
GetRefreshToken reads refresh_token cookie and returns it's value
func GetUserAuthToken ¶
GetUserAuthToken reads access_token cookie and returns it's value
func HandleABTestExit ¶ added in v0.4.0
func HandleCookieAndServ ¶ added in v0.4.0
func HandleCookieAndServ(w http.ResponseWriter, req *http.Request, n, o http.Handler, aspectID, domain string, randomiser Randomiser)
func Handler ¶ added in v0.5.0
func Handler(abTest bool, newHandler, oldHandler http.Handler, percentage int, aspectID, domain, exitNew string) http.HandlerFunc
Handler returns the relevant handler on the basis of the supplied parameters. It delegates to both abTestHandler and abTestPurgeHandler on the basis the abTest parameter, but it is really an encapsulation of the decision-making process as to what handler is used. Important - if AbTest is switched off it returns the new by default - this is to match router functionality.
func RemoveABTestCookieAspect ¶ added in v0.4.0
func RemoveABTestCookieAspect(w http.ResponseWriter, req *http.Request, aspectID, domain string)
func ServABTest ¶ added in v0.4.0
func ServABTest(w http.ResponseWriter, req *http.Request, n, o http.Handler, aspect ABTestCookieAspect)
func SetABTestCookieAspect ¶ added in v0.4.0
func SetABTestCookieAspect(w http.ResponseWriter, req *http.Request, aspectID, domain string, aspect ABTestCookieAspect)
func SetCollection ¶
func SetCollection(w http.ResponseWriter, value, domain string)
SetCollection sets a cookie containing collection ID
func SetIDToken ¶ added in v0.2.0
func SetIDToken(w http.ResponseWriter, idToken, domain string)
SetIDToken sets a cookie containing users id token ("id_token")
func SetLang ¶
func SetLang(w http.ResponseWriter, lang, domain string)
SetLang sets a cookie containing locale code
func SetPolicy ¶
func SetPolicy(w http.ResponseWriter, policy Policy, domain string)
SetPolicy sets a cookie with the users preferences, or sets default preferences on error
func SetPreferenceIsSet ¶
func SetPreferenceIsSet(w http.ResponseWriter, domain string)
SetPreferenceIsSet sets a cookie to record a user has set cookie preferences
func SetRefreshToken ¶ added in v0.2.0
func SetRefreshToken(w http.ResponseWriter, refreshToken, domain string)
SetRefreshToken sets a cookie containing users refresh token ("refresh_token")
func SetUserAuthToken ¶
func SetUserAuthToken(w http.ResponseWriter, userAuthToken, domain string)
SetUserAuthToken sets a cookie containing users auth token ("access token")
Types ¶
type ABTestCookieAspect ¶ added in v0.4.0
type ABTestCookieAspect struct { New CookieTime `json:"new,omitempty"` Old CookieTime `json:"old,omitempty"` }
func GetABTestCookieAspect ¶ added in v0.4.0
func GetABTestCookieAspect(req *http.Request, aspectID string) ABTestCookieAspect
type CookieTime ¶ added in v0.4.0
func MustParseCookieTime ¶ added in v0.4.0
func MustParseCookieTime(date string) CookieTime
MustParseCookieTime is a convenience function which is only for use in tests
func Now ¶ added in v0.4.0
func Now() CookieTime
func ParseCookieTime ¶ added in v0.4.0
func ParseCookieTime(datetime string) (CookieTime, error)
ParseCookieTime constructs a CookieTime from the given datetime parameter. If the parameter value does not conform to the 'cookieTimeFormat', an error is returned
func (CookieTime) Add ¶ added in v0.4.0
func (ct CookieTime) Add(d time.Duration) CookieTime
func (CookieTime) MarshalJSON ¶ added in v0.4.0
func (ct CookieTime) MarshalJSON() ([]byte, error)
func (CookieTime) String ¶ added in v0.4.0
func (ct CookieTime) String() string
func (*CookieTime) UnmarshalJSON ¶ added in v0.4.0
func (ct *CookieTime) UnmarshalJSON(js []byte) error
type InvalidCookieTimeString ¶ added in v0.4.0
type InvalidCookieTimeString struct {
// contains filtered or unexported fields
}
func (InvalidCookieTimeString) Error ¶ added in v0.4.0
func (ict InvalidCookieTimeString) Error() string
type PreferencesResponse ¶
PreferencesResponse is a combination of cookie policy and whether they have be set by user
func GetCookiePreferences ¶
func GetCookiePreferences(req *http.Request) PreferencesResponse
GetCookiePreferences returns a struct with all cookie preferences
type Randomiser ¶ added in v0.4.0
type Randomiser = func() ABTestCookieAspect