package ticket import ( "net/http" "strings" ) type Finder func(r *http.Request) string func DefaultFinder(r *http.Request) string { if s := FromHeader(r); s != "" { return s } if s := FromCookie(r); s != "" { return s } return FromQuery(r) } func FromCookie(r *http.Request) string { cookie, err := r.Cookie("ticket") if err != nil { return "" } return cookie.Value } func FromHeader(r *http.Request) string { bearer := r.Header.Get("Authorization") if len(bearer) > 7 && strings.ToUpper(bearer[0:6]) == "BEARER" { return bearer[7:] } return "" } func FromQuery(r *http.Request, keys ...string) string { q := r.URL.Query() for _, key := range keys { s := q.Get(key) if s != "" { return s } } return q.Get("ticket") }