Skip to content

Commit

Permalink
upgrade caddy version to 2.4.1 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
sillygod authored Jun 3, 2021
1 parent ad54c2d commit 4a3c6c1
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 465 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- name: set up go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.14.4'
go-version: '1.16.4'
id: go

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkt out
- name: checkt out
uses: actions/checkout@v2

# Runs test
Expand Down Expand Up @@ -62,6 +62,3 @@ jobs:
username: sillygod
password: ${{ secrets.GITHUB_TOKEN }}
tags: latest



6 changes: 2 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
- name: set up go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.14.4'
go-version: '1.16.4'
id: go

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: checkt out
- name: checkt out
uses: actions/checkout@v2

# Runs test
Expand All @@ -45,5 +45,3 @@ jobs:
- name: build
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o caddy cmd/main.go

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: set up go 1.x
uses: actions/setup-go@v2
with:
go-version: '1.14.4'
go-version: '1.16.4'
id: go

- name: checkout
Expand Down
4 changes: 1 addition & 3 deletions cmd/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

log {
output file /tmp/logs/caddy/access.log
format logfmt
format console
level debug
}

Expand All @@ -36,5 +36,3 @@
level info
}
}


20 changes: 10 additions & 10 deletions endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func (c cachePurge) handleShowCache(w http.ResponseWriter, r *http.Request) erro

if r.Method != http.MethodGet {
return caddy.APIError{
Code: http.StatusMethodNotAllowed,
Err: fmt.Errorf("method not allowed"),
HTTPStatus: http.StatusMethodNotAllowed,
Err: fmt.Errorf("method not allowed"),
}
}

Expand Down Expand Up @@ -172,8 +172,8 @@ func (c cachePurge) handleListCacheKeys(w http.ResponseWriter, r *http.Request)

if r.Method != http.MethodGet {
return caddy.APIError{
Code: http.StatusMethodNotAllowed,
Err: fmt.Errorf("method not allowed"),
HTTPStatus: http.StatusMethodNotAllowed,
Err: fmt.Errorf("method not allowed"),
}
}

Expand All @@ -184,8 +184,8 @@ func (c cachePurge) handleListCacheKeys(w http.ResponseWriter, r *http.Request)
err := json.NewEncoder(w).Encode(keys)
if err != nil {
return caddy.APIError{
Code: http.StatusBadRequest,
Err: err,
HTTPStatus: http.StatusBadRequest,
Err: err,
}
}

Expand All @@ -196,8 +196,8 @@ func (c cachePurge) handleListCacheKeys(w http.ResponseWriter, r *http.Request)
func (c cachePurge) handlePurge(w http.ResponseWriter, r *http.Request) error {
if r.Method != http.MethodDelete {
return caddy.APIError{
Code: http.StatusMethodNotAllowed,
Err: fmt.Errorf("method not allowed"),
HTTPStatus: http.StatusMethodNotAllowed,
Err: fmt.Errorf("method not allowed"),
}
}

Expand All @@ -208,8 +208,8 @@ func (c cachePurge) handlePurge(w http.ResponseWriter, r *http.Request) error {
_, err := io.Copy(buf, r.Body)
if err != nil {
return caddy.APIError{
Code: http.StatusBadRequest,
Err: fmt.Errorf("reading request body: %s", err.Error()),
HTTPStatus: http.StatusBadRequest,
Err: fmt.Errorf("reading request body: %s", err.Error()),
}
}

Expand Down
15 changes: 7 additions & 8 deletions endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CacheEndpointTestSuite struct {
suite.Suite
caddyTester *caddytest.Tester
url string
admin_url string
}

func (suite *CacheEndpointTestSuite) assertKeyNotIn(key string, keys []string, msgAndArgs ...interface{}) {
Expand Down Expand Up @@ -46,10 +47,10 @@ func (suite *CacheEndpointTestSuite) assertKeyIn(key string, keys []string, msgA
func (suite *CacheEndpointTestSuite) SetupSuite() {
suite.caddyTester = caddytest.NewTester(suite.T())
suite.url = "http://localhost:9898/hello"
suite.admin_url = "http://localhost:2019"
suite.caddyTester.InitServer(`
{
order http_cache before reverse_proxy
admin 0.0.0.0:7777
}
:9898 {
Expand All @@ -68,9 +69,7 @@ func (suite *CacheEndpointTestSuite) SetupSuite() {
respond /hello 200 {
body "hope anything will be good"
}
}
`, "caddyfile")
}`, "caddyfile")
}

func (suite *CacheEndpointTestSuite) TestListCacheKeys() {
Expand All @@ -81,7 +80,7 @@ func (suite *CacheEndpointTestSuite) TestListCacheKeys() {
suite.Assert().NoError(err)
// create the cache first

r, err = http.NewRequest("GET", "http://localhost:7777/caches", nil)
r, err = http.NewRequest("GET", suite.admin_url+"/caches", nil)
suite.Assert().NoError(err)

res, err = suite.caddyTester.Client.Do(r)
Expand All @@ -95,7 +94,7 @@ func (suite *CacheEndpointTestSuite) TestListCacheKeys() {
}

func (suite *CacheEndpointTestSuite) TestHealthCheck() {
r, err := http.NewRequest("GET", "http://localhost:7777/health", nil)
r, err := http.NewRequest("GET", suite.admin_url+"/health", nil)
suite.Assert().NoError(err)
_, err = suite.caddyTester.Client.Do(r)
suite.Assert().NoError(err)
Expand All @@ -108,7 +107,7 @@ func (suite *CacheEndpointTestSuite) TestShowCache() {
_, err = suite.caddyTester.Client.Do(r)
suite.Assert().NoError(err)
// create the cache first
url := fmt.Sprintf("http://localhost:7777/caches/%s", url.PathEscape("GET localhost/hello?"))
url := fmt.Sprintf("%s/caches/%s", suite.admin_url, url.PathEscape("GET localhost/hello?"))

r, err = http.NewRequest("GET", url, nil)
suite.Assert().NoError(err)
Expand Down Expand Up @@ -159,7 +158,7 @@ func (suite *CacheEndpointTestSuite) TestPurgeCache() {
suite.Assert().NoError(err)
// create the cache first

r, err = http.NewRequest("DELETE", "http://localhost:7777/caches/purge", bytes.NewBuffer(data.body))
r, err = http.NewRequest("DELETE", suite.admin_url+"/caches/purge", bytes.NewBuffer(data.body))
suite.Assert().NoError(err)
r.Header.Set("Content-Type", "application/json")

Expand Down
36 changes: 10 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
module github.com/sillygod/cdp-cache

go 1.14
go 1.16

require (
github.com/armon/go-metrics v0.3.3 // indirect
github.com/caddyserver/caddy/v2 v2.1.1
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/containerd/continuity v0.0.0-20200710164510-efbc4488d8fe // indirect
github.com/go-redis/redis v6.15.8+incompatible
github.com/google/uuid v1.1.1
github.com/hashicorp/consul/api v1.5.0
github.com/hashicorp/go-hclog v0.14.1 // indirect
github.com/hashicorp/go-immutable-radix v1.2.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.9.2 // indirect
github.com/caddyserver/caddy/v2 v2.4.1
github.com/go-redis/redis v6.15.9+incompatible
github.com/google/uuid v1.2.0
github.com/hashicorp/consul/api v1.8.1
github.com/influxdata/influxdb-client-go v1.4.0
github.com/mailgun/groupcache/v2 v2.2.0
github.com/mitchellh/go-testing-interface v1.0.3 // indirect
github.com/mitchellh/mapstructure v1.3.1 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/ory/dockertest/v3 v3.6.0
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35
github.com/stretchr/testify v1.6.1
go.uber.org/zap v1.15.0
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d // indirect
github.com/mailgun/groupcache/v2 v2.2.1
github.com/ory/dockertest/v3 v3.6.5
github.com/pquerna/cachecontrol v0.1.0
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.17.0
)
Loading

0 comments on commit 4a3c6c1

Please sign in to comment.