Cody Joyce 2 months ago
parent
commit
8163e4955e
1 changed files with 11 additions and 4 deletions
  1. 11 4
      srv/res.go

+ 11 - 4
srv/res.go

@@ -7,19 +7,26 @@ import (
 )
 
 type Res struct {
-	w      http.ResponseWriter
-	r      *http.Request
-	status int
+	w       http.ResponseWriter
+	r       *http.Request
+	status  int
+	cookies map[string]*http.Cookie
 }
 
 func (res *Res) Construct(w http.ResponseWriter, r *http.Request) {
 	res.w = w
 	res.r = r
 	res.status = 200
+	res.cookies = make(map[string]*http.Cookie)
 }
 
 func (res *Res) Send(txt string) {
+	for _, v := range res.cookies {
+		http.SetCookie(res.w, v)
+	}
+
 	res.w.WriteHeader(res.status)
+
 	fmt.Fprint(res.w, txt)
 }
 
@@ -57,6 +64,6 @@ func (res *Res) Cookie(name string, val string, expires ...time.Time) *Res {
 		SameSite: http.SameSiteStrictMode,
 	}
 
-	http.SetCookie(res.w, cookie)
+	res.cookies[name] = cookie
 	return res
 }