Skip to content

refactor: unify Cookie API to return string and map[string]string - #24

Merged
kk0829 merged 3 commits into
mainfrom
refactor/cookie-api
Apr 2, 2026
Merged

kk0829 merged 3 commits into
mainfrom
refactor/cookie-api

Conversation

@kk0829

@kk0829 kk0829 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR unifies the Cookie API to align with the framework's design style.

Breaking Changes

  • Cookie() return type changed from *fasthttp.Cookie to string
  • Cookies() return type changed from []*fasthttp.Cookie to map[string]string

Bug Fixes

  • Fixed dangling pointer bug in internal cookie() method

API Changes

Before

cookie := ctx.Cookie("sid")
if cookie != nil {
    value := string(cookie.Value())
}

for _, c := range ctx.Cookies() {
    fmt.Println(string(c.Key()), string(c.Value()))
}

After

value := ctx.Cookie("sid")
if value != "" {
    // use value
}

for name, value := range ctx.Cookies() {
    fmt.Println(name, value)
}

Benefits

  1. No longer exposes underlying fasthttp types
  2. Consistent with other framework methods (Query, Param, Header)
  3. Simpler usage, no nil checks needed
  4. Fixed memory safety bug

- Change Cookie() return type from *fasthttp.Cookie to string
- Change Cookies() return type from []*fasthttp.Cookie to map[string]string
- Fix dangling pointer bug in cookie() method
- Update all tests and examples to use new API
- Align with framework style (Query, Param, Header methods)
- Change Cookie() return type from *fasthttp.Cookie to string
- Change Cookies() return type from []*fasthttp.Cookie to map[string]string
- Fix dangling pointer bug in cookie() method
- Update all tests and examples to use new API
- Align with framework style (Query, Param, Header methods)
@kk0829 kk0829 added bug Something isn't working enhancement New feature or request labels Apr 2, 2026
@kk0829
kk0829 merged commit aa268d7 into main Apr 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants