From 11312ef5feebb09aefaa89f0971b2cc4cff9306e Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 24 Oct 2024 20:12:16 -0300 Subject: [PATCH] refactor(cookies): move errors to bottom of file --- lib/cookies/cookies.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/cookies/cookies.go b/lib/cookies/cookies.go index 0091254..0f1e027 100644 --- a/lib/cookies/cookies.go +++ b/lib/cookies/cookies.go @@ -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) +}