Skip to content

Commit

Permalink
restructure to shorten line lengths to pass linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dbhoot committed Mar 10, 2024
1 parent 6eded88 commit 6b6a3da
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cors

import (
"errors"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -108,10 +109,21 @@ func (c Config) validateAllowedSchemas(origin string) bool {

// Validate is check configuration of user defined.
func (c Config) Validate() error {
if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0 || c.AllowOriginWithContextFunc != nil) {
return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOriginFuncWithContext or AllowOrigins is not needed")
hasOriginFn := c.AllowOriginFunc != nil
hasOriginFn = hasOriginFn || c.AllowOriginWithContextFunc != nil

if c.AllowAllOrigins && (hasOriginFn || len(c.AllowOrigins) > 0) {
originFields := strings.Join([]string{
"AllowOriginFunc",
"AllowOriginFuncWithContext",
"AllowOrigins",
}, " or ")
return fmt.Errorf(
"conflict settings: all origins enabled. %s is not needed.",
originFields,
)
}
if !c.AllowAllOrigins && c.AllowOriginFunc == nil && c.AllowOriginWithContextFunc == nil && len(c.AllowOrigins) == 0 {
if !c.AllowAllOrigins && !hasOriginFn && len(c.AllowOrigins) == 0 {
return errors.New("conflict settings: all origins disabled")

Check failure on line 127 in cors.go

View workflow job for this annotation

GitHub Actions / lint

ST1005: error strings should not end with punctuation or newlines (stylecheck)
}
for _, origin := range c.AllowOrigins {
Expand Down

0 comments on commit 6b6a3da

Please sign in to comment.