1 package sessions 2 3 import ( 4 "net/http" 5 "time" 6 ) 7 8 type optFunc func(*store) 9 10 // Name sets the cookie name. 11 func Name(name string) optFunc { 12 return func(s *store) { 13 s.cookie.Name = name 14 } 15 } 16 17 // Domain sets the optional domain for the cookie. 18 func Domain(domain string) optFunc { 19 return func(s *store) { 20 s.cookie.Domain = domain 21 } 22 } 23 24 // Path sets the optional path for the cookie. 25 func Path(path string) optFunc { 26 return func(s *store) { 27 s.cookie.Path = path 28 } 29 } 30 31 // HTTPOnly sets the httponly flag on the cookie. 32 func HTTPOnly() optFunc { 33 return func(s *store) { 34 s.cookie.HttpOnly = true 35 } 36 } 37 38 // Secure sets the secure flag on the cookie. 39 func Secure() optFunc { 40 return func(s *store) { 41 s.cookie.Secure = true 42 } 43 } 44 45 // Expiry sets a maximum time that a cookie and authenticated message are valid 46 // for. 47 func Expiry(d time.Duration) optFunc { 48 return func(s *store) { 49 s.expires = d 50 } 51 } 52 53 // SameSite sets the SameSite flag on the cookie. 54 func SameSite(ss http.SameSite) optFunc { 55 return func(s *store) { 56 s.cookie.SameSite = ss 57 } 58 } 59 60 // Sign causes the Encoder to sign the data, as opposed to encrypting it. 61 func Sign() optFunc { 62 return func(s *store) { 63 s.sign = true 64 } 65 } 66