diff --git a/cors.go b/cors.go index cacb34a..bf93b59 100644 --- a/cors.go +++ b/cors.go @@ -104,7 +104,7 @@ func (c Config) getAllowedSchemas() []string { return allowedSchemas } -var regexpBasedOrigin = regexp.MustCompile(`^\/(.+)\/[gimuy]?$`) +var regexpBasedOrigin = regexp.MustCompile(`^/(.+)/[gimuy]?$`) func (c Config) validateAllowedSchemas(origin string) bool { allowedSchemas := c.getAllowedSchemas() @@ -140,11 +140,11 @@ func (c Config) Validate() error { ) } if !c.AllowAllOrigins && !hasOriginFn && len(c.AllowOrigins) == 0 { - return errors.New("conflict settings: all origins disabled") + return errors.New("conflict settings: all origins disabled. Specify either AllowAllOrigins, AllowOrigins or an AllowOriginFunc") } for _, origin := range c.AllowOrigins { if !strings.Contains(origin, "*") && !c.validateAllowedSchemas(origin) { - return errors.New("bad origin: origins must contain '*' or include " + strings.Join(c.getAllowedSchemas(), ",")) + return fmt.Errorf("bad origin ('%s'): origins must contain '*' or include %s", origin, strings.Join(c.getAllowedSchemas(), ",")) } } return nil @@ -162,8 +162,9 @@ func (c Config) parseWildcardRules() [][]string { continue } - if c := strings.Count(o, "*"); c > 1 { - panic(errors.New("only one * is allowed").Error()) + if count := strings.Count(o, "*"); count > 1 { + err := fmt.Errorf("only one * is allowed. actual value is: %s", c.AllowOrigins) + panic(err.Error()) } i := strings.Index(o, "*")