Skip to content

Commit

Permalink
fix misspell and add workflow for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
sillygod committed May 15, 2020
1 parent 3fe27c9 commit 0edc997
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: PR-CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
test:
# The type of runner that the job will run on
name: Test
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: set up go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go

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

# Runs test
- name: run test
run: |
go test ./...
- 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 backends/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ func TestSubscription(t *testing.T) {
<-ended
})

}
}
3 changes: 3 additions & 0 deletions backends/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func InitGroupCacheRes(maxSize int) error {
return err
}
_, err = atch.Join(nil)
if err != nil {
return err
}
}

if pool == nil {
Expand Down
2 changes: 1 addition & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func judgeResponseShouldCacheOrNot(req *http.Request,

var reqHeaders http.Header
var reqMethod string
var reqDir *cacheobject.RequestCacheDirectives

var reqDir *cacheobject.RequestCacheDirectives = nil
respDir, err := cacheobject.ParseResponseCacheControl(respHeaders.Get("Cache-Control"))
if err != nil {
return nil, time.Time{}, nil, nil, err
Expand Down
5 changes: 2 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (h *Handler) Validate() error {

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {

// add a log here to record the elapsed time (from receiving the request to send the reponse)
// add a log here to record the elapsed time (from receiving the request to send the response)
start := time.Now()
upstreamDuration := time.Duration(0)

Expand Down Expand Up @@ -207,7 +207,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
}

key := getKey(h.Config.CacheKeyTemplate, r)
lock := h.URLLocks.Adquire(key)
lock := h.URLLocks.Acquire(key)
defer lock.Unlock()

// Lookup correct entry
Expand All @@ -220,7 +220,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
if err := h.respond(w, previousEntry, cacheHit); err == nil {
return nil
}
exists = false
}

// Second case: CACHE SKIP
Expand Down
4 changes: 4 additions & 0 deletions readme.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#+HTML: <a href="https://goreportcard.com/report/github.com/sillygod/cdp-cache"><img src="https://goreportcard.com/badge/github.com/sillygod/cdp-cache" /></a>
#+HTML: </div>


* Caddy Http Cache

This is a http cache plugin for caddy 2. In fact, I am not familiar with the mechanism of the cdn cache so I borrow the code from https://github.com/nicolasazrak/caddy-cache. which is the caddy v1's cache module. Then, I migrate the codebase to be consist with the caddy2 architecture, do some change, and implement more feature for it.
Expand Down
4 changes: 2 additions & 2 deletions url_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func NewURLLock(config *Config) *URLLock {
}
}

// Adquire a lock for given key
func (allLocks *URLLock) Adquire(key string) *sync.Mutex {
// Acquire a lock for given key
func (allLocks *URLLock) Acquire(key string) *sync.Mutex {
bucketIndex := allLocks.getBucketIndexForKey(key)
allLocks.globalLocks[bucketIndex].Lock()
defer allLocks.globalLocks[bucketIndex].Unlock()
Expand Down

0 comments on commit 0edc997

Please sign in to comment.