Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
Homulvas committed May 13, 2024
1 parent 91a3a4c commit d38c734
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ jobs:

strategy:
matrix:
go-version: [ 1.19, 1.x ]
go-version: [ 1.22, 1.x ]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

# https://github.com/marketplace/actions/checkout
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v3
uses: actions/cache@v4
with:
# In order:
# * Module download cache
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
name: Main Process
runs-on: ubuntu-latest
env:
GO_VERSION: 1.19
GOLANGCI_LINT_VERSION: v1.50.0
YAEGI_VERSION: v0.14.2
GO_VERSION: 1.22
GOLANGCI_LINT_VERSION: v1.58.1
YAEGI_VERSION: v0.16.1
CGO_ENABLED: 0
defaults:
run:
Expand All @@ -24,20 +24,20 @@ jobs:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

# https://github.com/marketplace/actions/checkout
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: go/src/github.com/${{ github.repository }}
fetch-depth: 0

# https://github.com/marketplace/actions/cache
- name: Cache Go modules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
Expand Down
2 changes: 1 addition & 1 deletion .traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ displayName: Demo Plugin
type: middleware
iconPath: .assets/icon.png

import: github.com/traefik/plugindemo
import: github.com/argyle-engineering/traefik-ratelimiter-middleware

summary: '[Demo] Add Request Header'

Expand Down
6 changes: 3 additions & 3 deletions demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package plugindemo
import (
"bytes"
"context"
"fmt"
"errors"
"net/http"
"text/template"
)
Expand All @@ -30,9 +30,9 @@ type Demo struct {
}

// New created a new Demo plugin.
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
func New(_ context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
if len(config.Headers) == 0 {
return nil, fmt.Errorf("headers cannot be empty")
return nil, errors.New("headers cannot be empty")
}

return &Demo{
Expand Down
10 changes: 4 additions & 6 deletions demo_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package plugindemo_test
package plugindemo

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/traefik/plugindemo"
)

func TestDemo(t *testing.T) {
cfg := plugindemo.CreateConfig()
cfg := CreateConfig()
cfg.Headers["X-Host"] = "[[.Host]]"
cfg.Headers["X-Method"] = "[[.Method]]"
cfg.Headers["X-URL"] = "[[.URL]]"
cfg.Headers["X-URL"] = "[[.URL]]"
cfg.Headers["X-Demo"] = "test"

ctx := context.Background()
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
next := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})

handler, err := plugindemo.New(ctx, next, cfg, "demo-plugin")
handler, err := New(ctx, next, cfg, "demo-plugin")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/traefik/plugindemo
module github.com/argyle-engineering/traefik-ratelimiter-middleware

go 1.19
go 1.22

0 comments on commit d38c734

Please sign in to comment.