Skip to content

Commit

Permalink
feat: added cookies attributes struct and SetCookie function
Browse files Browse the repository at this point in the history
  • Loading branch information
ralvarezdev committed Feb 1, 2025
1 parent 46814f5 commit 7cdd75d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions http/cookie/cookie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cookie

import (
"net/http"
"time"
)

// Attributes is the structure for the attributes of a cookie
type Attributes struct {
Name string
Path string
Domain string
ExpiresAt time.Time
Secure bool
HTTPOnly bool
SameSite http.SameSite
}

// SetCookie sets a cookie
func SetCookie(
w http.ResponseWriter,
attributes *Attributes,
value string,
) {
// Create and create cookie
cookie := &http.Cookie{
Name: attributes.Name,
Value: value,
Path: attributes.Path,
Domain: attributes.Domain,
Expires: attributes.ExpiresAt,
Secure: attributes.Secure,
HttpOnly: attributes.HTTPOnly,
SameSite: attributes.SameSite,
}
http.SetCookie(w, cookie)
}

0 comments on commit 7cdd75d

Please sign in to comment.