From dc73b7adf25529490ea390ff1fb2bbbad8cbd4f1 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Mon, 19 Jun 2023 20:48:16 +0200 Subject: [PATCH] chore: small CORS refactoring Signed-off-by: Valery Piashchynski --- .github/workflows/linters.yml | 4 ++-- .golangci.yml | 1 - config.go | 10 +++------- plugin.go | 29 ++++++++++++++--------------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index c96264d..79294b8 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -13,11 +13,11 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 # action page: with: - go-version: 1.19 + go-version: stable - name: Run linter uses: golangci/golangci-lint-action@v3.6.0 # Action page: with: - version: v1.50 # without patch version + version: v1.53 # without patch version only-new-issues: false # show only new issues if it's a pull request args: --timeout=10m --build-tags=race diff --git a/.golangci.yml b/.golangci.yml index 7e26a5d..8dbbc2b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,7 +44,6 @@ linters: # All available linters list: 0 { - p.cors.MaxAge = p.cfg.CORS.MaxAge + opts.MaxAge = p.cfg.CORS.MaxAge } - if p.cfg.CORS.AllowCredentials != nil { - p.cors.AllowCredentials = *p.cfg.CORS.AllowCredentials - } + opts.AllowCredentials = p.cfg.CORS.AllowCredentials if p.cfg.CORS.OptionsSuccessStatus != 0 { - p.cors.OptionsSuccessStatus = p.cfg.CORS.OptionsSuccessStatus + opts.OptionsSuccessStatus = p.cfg.CORS.OptionsSuccessStatus } + + p.cors = cors.New(opts) } return nil @@ -101,7 +100,7 @@ func (p *Plugin) Init(cfg Configurer) error { func (p *Plugin) Middleware(next http.Handler) http.Handler { // Configure CORS handler if p.cors != nil { - next = cors.New(*p.cors).Handler(next) + next = p.cors.Handler(next) } // Define the http.HandlerFunc