http/cors.go
func (s *CORSHandler) CreatePreflight(routes Routes) Routes {
	list := make(Routes, 0, len(routes))
	hList := make(map[string]*CORSPreflight, len(routes))
	for _, v := range routes {
		preflight, ok := hList[v.Path]
		if !ok {
			preflight = &CORSPreflight{
				*s,
				make([]string, 0, 1),
				v.MustAuth,
			}
			hList[v.Path] = preflight
		}

		preflight.Methods = append(preflight.Methods, v.Method)
		if v.MustAuth {
			preflight.UseCredentials = true
		}
	}

	for k, v := range hList {
		list = append(list, Route{
			Name:       "",
			Method:     DEFAULT_CORS_PREFLIGHT_METHOD,
			Path:       k,
			MustAuth:   v.UseCredentials,
			ActionFunc: v.ServeHTTP,
		})
	}
	return list
}
func (s *CORSHandler) CreatePreflight(routes Routes) Routes {
	list := make(Routes, 0, len(routes))
	hList := make(map[string]*CORSPreflight, len(routes))
	for _, v := range routes {
		preflight, ok := hList[v.Path]
		if !ok {
			preflight = &CORSPreflight{
				*s,
				make([]string, 0, 1),
				v.MustAuth,
			}
			hList[v.Path] = preflight
		}

		preflight.Methods = append(preflight.Methods, v.Method)
		if v.MustAuth {
			preflight.UseCredentials = true
		}
	}

	for k, v := range hList {
		list = append(list, Route{
			Name:       "",
			Method:     DEFAULT_CORS_PREFLIGHT_METHOD,
			Path:       k,
			MustAuth:   v.UseCredentials,
			ActionFunc: v.ServeHTTP,
		})
	}
	return list
}
func ( s * CORSHandler ) CreatePreflight ( routes Routes ) Routes { list := make ( Routes , 0 , len ( routes ) ) hList := make ( map [ string ] * CORSPreflight , len ( routes ) ) for _ , v := range routes { preflight , ok := hList [ v . Path ] if ! ok { preflight = & CORSPreflight { * s , make ( [ ] string , 0 , 1 ) , v . MustAuth , } hList [ v . Path ] = preflight } preflight . Methods = append ( preflight . Methods , v . Method ) if v . MustAuth { preflight . UseCredentials = true } } for k , v := range hList { list = append ( list , Route { Name : " " , Method : DEFAULT_CORS_PREFLIGHT_METHOD , Path : k , MustAuth : v . UseCredentials , ActionFunc : v . ServeHTTP , } ) } return list }
// CreatePreflight creates HTTP routes that handles pre-flight requests.
CreatePreflight creates HTTP routes that handles pre - flight requests .