1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
package stickycookie
import (
"errors"
"net/url"
)
// FallbackValue manages hashed sticky value.
type FallbackValue struct {
from CookieValue
to CookieValue
}
// NewFallbackValue creates a new FallbackValue.
func NewFallbackValue(from CookieValue, to CookieValue) (*FallbackValue, error) {
if from == nil || to == nil {
return nil, errors.New("from and to are mandatory")
}
return &FallbackValue{from: from, to: to}, nil
}
// Get hashes the sticky value.
func (v *FallbackValue) Get(raw *url.URL) string {
return v.to.Get(raw)
}
// FindURL gets url from array that match the value.
// If it is a symmetric algorithm, it decodes the URL, otherwise it compares the ciphered values.
func (v *FallbackValue) FindURL(raw string, urls []*url.URL) (*url.URL, error) {
findURL, err := v.from.FindURL(raw, urls)
if findURL != nil {
return findURL, err
}
return v.to.FindURL(raw, urls)
}
|