refactor(cookies): move errors to bottom of file

This commit is contained in:
Guz
2024-10-24 20:12:16 -03:00
parent d74d71dfa3
commit 11312ef5fe

View File

@@ -22,27 +22,6 @@ type Unmarshaler interface {
UnmarshalCookie(*http.Cookie) error
}
var (
ErrDecodeBase64 = errors.New("Failed to decode base64 string from cookie value")
ErrMarshal = errors.New("Failed to marhal JSON value for cookie value")
ErrUnmarshal = errors.New("Failed to unmarshal JSON value from cookie value")
ErrReflectPanic = errors.New("Reflect panic while trying to get tag from value")
ErrMissingName = errors.New("Failed to get name of cookie")
)
type ErrNoCookie struct {
name string
}
func (e ErrNoCookie) Error() string {
return fmt.Sprintf("Cookie \"%s\" missing from request", e.name)
}
var COOKIE_EXPIRE_VALID_FORMATS = []string{
time.DateOnly, time.DateTime,
time.RFC1123, time.RFC1123Z,
}
func Marshal(v any) (*http.Cookie, error) {
if m, ok := v.(Marshaler); ok {
return m.MarshalCookie()
@@ -115,6 +94,11 @@ func marshalValue(v any) (*http.Cookie, error) {
}, nil
}
var COOKIE_EXPIRE_VALID_FORMATS = []string{
time.DateOnly, time.DateTime,
time.RFC1123, time.RFC1123Z,
}
func setCookieProps(c *http.Cookie, v any) error {
tag, err := getCookieTag(v)
if err != nil {
@@ -275,3 +259,19 @@ func timeParseMultiple(v string, formats ...string) (time.Time, error) {
return time.Time{}, errs[len(errs)-1]
}
var (
ErrDecodeBase64 = errors.New("Failed to decode base64 string from cookie value")
ErrMarshal = errors.New("Failed to marhal JSON value for cookie value")
ErrUnmarshal = errors.New("Failed to unmarshal JSON value from cookie value")
ErrReflectPanic = errors.New("Reflect panic while trying to get tag from value")
ErrMissingName = errors.New("Failed to get name of cookie")
)
type ErrNoCookie struct {
name string
}
func (e ErrNoCookie) Error() string {
return fmt.Sprintf("Cookie \"%s\" missing from request", e.name)
}