Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: The HTTP module supports set Cookie #49

Merged
merged 7 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ jobs:
with:
go-version: 'stable'
cache: false
- name: go mod pakcage cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }}
- name: Install dependencies
run: go mod tidy
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions context_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (r *ContextRequest) Bind(obj any) error {
return r.instance.BodyParser(obj)
}

func (r *ContextRequest) Cookie(key string, defaultValue ...string) string {
return r.instance.Cookies(key, defaultValue...)
}

func (r *ContextRequest) Form(key string, defaultValue ...string) string {
if len(defaultValue) == 0 {
return r.instance.FormValue(key)
Expand Down
25 changes: 25 additions & 0 deletions context_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ func NewContextResponse(instance *fiber.Ctx, origin contractshttp.ResponseOrigin
return &ContextResponse{instance, origin}
}

func (r *ContextResponse) Cookie(cookie contractshttp.Cookie) contractshttp.ContextResponse {
r.instance.Cookie(&fiber.Cookie{
Name: cookie.Name,
Value: cookie.Value,
Path: cookie.Path,
Domain: cookie.Domain,
Expires: cookie.Expires,
Secure: cookie.Secure,
HTTPOnly: cookie.HttpOnly,
MaxAge: cookie.MaxAge,
SameSite: cookie.SameSite,
})

return r
}

func (r *ContextResponse) Data(code int, contentType string, data []byte) contractshttp.Response {
return &DataResponse{code, contentType, data, r.instance}
}
Expand Down Expand Up @@ -67,6 +83,15 @@ func (r *ContextResponse) Flush() {
r.instance.Fresh()
}

func (r *ContextResponse) WithoutCookie(name string) contractshttp.ContextResponse {
r.instance.Cookie(&fiber.Cookie{
Name: name,
MaxAge: -1,
})

return r
}

func (r *ContextResponse) Writer() http.ResponseWriter {
return &WriterAdapter{r.instance}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
kkumar-gcc marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/gofiber/template/html/v2 v2.0.5
github.com/gookit/color v1.5.4
github.com/gookit/validate v1.5.1
github.com/goravel/framework v1.13.1-0.20231121034700-e91df530a997
github.com/goravel/framework v1.13.1-0.20231214150751-ea46f55b93db
github.com/savioxavier/termlink v1.3.0
github.com/spf13/cast v1.6.0
github.com/stretchr/testify v1.8.4
Expand Down