github.com/gogf/gf/v2@v2.7.4/net/ghttp/ghttp_server_config_cookie.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package ghttp 8 9 import ( 10 "net/http" 11 "time" 12 ) 13 14 // SetCookieMaxAge sets the CookieMaxAge for server. 15 func (s *Server) SetCookieMaxAge(ttl time.Duration) { 16 s.config.CookieMaxAge = ttl 17 } 18 19 // SetCookiePath sets the CookiePath for server. 20 func (s *Server) SetCookiePath(path string) { 21 s.config.CookiePath = path 22 } 23 24 // SetCookieDomain sets the CookieDomain for server. 25 func (s *Server) SetCookieDomain(domain string) { 26 s.config.CookieDomain = domain 27 } 28 29 // GetCookieMaxAge returns the CookieMaxAge of the server. 30 func (s *Server) GetCookieMaxAge() time.Duration { 31 return s.config.CookieMaxAge 32 } 33 34 // GetCookiePath returns the CookiePath of server. 35 func (s *Server) GetCookiePath() string { 36 return s.config.CookiePath 37 } 38 39 // GetCookieDomain returns CookieDomain of server. 40 func (s *Server) GetCookieDomain() string { 41 return s.config.CookieDomain 42 } 43 44 // GetCookieSameSite return CookieSameSite of server. 45 func (s *Server) GetCookieSameSite() http.SameSite { 46 switch s.config.CookieSameSite { 47 case "lax": 48 return http.SameSiteLaxMode 49 case "none": 50 return http.SameSiteNoneMode 51 case "strict": 52 return http.SameSiteStrictMode 53 default: 54 return http.SameSiteDefaultMode 55 } 56 } 57 58 func (s *Server) GetCookieSecure() bool { 59 return s.config.CookieSecure 60 } 61 62 func (s *Server) GetCookieHttpOnly() bool { 63 return s.config.CookieHttpOnly 64 }