-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added cookies attributes struct and SetCookie function
- Loading branch information
1 parent
46814f5
commit 7cdd75d
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |