Skip to content

Commit 715e90f

Browse files
committed
feat: add cookie parameter support and related tests
1 parent dfe6ab8 commit 715e90f

11 files changed

Lines changed: 1464 additions & 292 deletions

File tree

ROADMAP.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
- [ ] Response Headers
77
- [ ] Non-json responses
88
- [ ] Middleware
9-
- [ ] Cookie as param injection
109
- [ ] Response Cookies
1110
- [ ] Streaming responses
1211

pkg/framework/fiberframework/request.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func (r *fiberRequest) GetFormValue(key string) string {
3737
return r.c.FormValue(key)
3838
}
3939

40+
func (r *fiberRequest) GetCookieValue(key string) string {
41+
return r.c.Cookies(key)
42+
}
43+
4044
func (r *fiberRequest) GetFile(key string) (*multipart.FileHeader, error) {
4145
return r.c.FormFile(key)
4246
}

pkg/framework/ginframework/request.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func (r *ginRequest) GetFormValue(key string) string {
3737
return r.c.PostForm(key)
3838
}
3939

40+
func (r *ginRequest) GetCookieValue(key string) string {
41+
cookie, err := r.c.Cookie(key)
42+
if err != nil {
43+
return ""
44+
}
45+
return cookie
46+
}
47+
4048
func (r *ginRequest) GetFile(key string) (*multipart.FileHeader, error) {
4149
return r.c.FormFile(key)
4250
}

pkg/framework/iface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type FrameworkRequest interface {
2727
GetPathParam(key string) string
2828
GetQueryParam(key string) string
2929
GetFormValue(key string) string
30+
GetCookieValue(key string) string
3031
GetFile(key string) (*multipart.FileHeader, error)
3132
}
3233

pkg/reflection/reflection.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func PopulateValueFromTypeUsingContext(f framework.FrameworkRequest, pType refle
7878
return err
7979
}
8080
}
81+
} else if pType.Field(i).Tag.Get("cookie") != "" {
82+
if pVal.Field(i).Type().Kind() != reflect.Ptr || f.GetCookieValue(pType.Field(i).Tag.Get("cookie")) != "" {
83+
err := setValue(pVal.Field(i), f.GetCookieValue(pType.Field(i).Tag.Get("cookie")), pType.Field(i).Name)
84+
if err != nil {
85+
return err
86+
}
87+
}
8188
}
8289
}
8390

0 commit comments

Comments
 (0)