github.com/blend/go-sdk@v1.20220411.3/webutil/parse_same_site.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package webutil 9 10 import ( 11 "net/http" 12 13 "github.com/blend/go-sdk/ex" 14 ) 15 16 // MustParseSameSite parses a string value for same site and panics on error. 17 func MustParseSameSite(sameSite string) http.SameSite { 18 value, err := ParseSameSite(sameSite) 19 if err != nil { 20 panic(err) 21 } 22 return value 23 } 24 25 // ParseSameSite parses a string value for same site. 26 func ParseSameSite(sameSite string) (http.SameSite, error) { 27 switch sameSite { 28 case SameSiteStrict: 29 return http.SameSiteStrictMode, nil 30 case SameSiteLax: 31 return http.SameSiteLaxMode, nil 32 case SameSiteDefault: 33 return http.SameSiteDefaultMode, nil 34 default: 35 return http.SameSite(-1), ex.New(ErrInvalidSameSite, ex.OptMessagef("value: %s", sameSite)) 36 } 37 }