cookies

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 11 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
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)}
	}
}
View Source
var ErrABTestCookieNotFound = errors.New("a/b test cookie not found")

ErrABTestCookieNotFound is used when a/b test cookie isn't found

Functions

func GetCollection

func GetCollection(req *http.Request) (string, error)

GetCollection reads collection_id cookie and returns it's value

func GetIDToken added in v0.2.0

func GetIDToken(req *http.Request) (string, error)

GetIDToken reads id_token cookie and returns it's value

func GetLang

func GetLang(req *http.Request) (string, error)

GetLang reads lang cookie and returns it's value

func GetRefreshToken added in v0.2.0

func GetRefreshToken(req *http.Request) (string, error)

GetRefreshToken reads refresh_token cookie and returns it's value

func GetUserAuthToken

func GetUserAuthToken(req *http.Request) (string, error)

GetUserAuthToken reads access_token cookie and returns it's value

func HandleABTestExit added in v0.4.0

func HandleABTestExit(w http.ResponseWriter, req *http.Request, o http.Handler, aspectID, domain string)

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

type CookieTime struct {
	time.Time
}

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 Policy

type Policy struct {
	Essential bool `json:"essential"`
	Usage     bool `json:"usage"`
}

Policy is cookie policy setting choosen by a user

type PreferencesResponse

type PreferencesResponse struct {
	IsPreferenceSet bool
	Policy          Policy
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL