-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add escape support and support Caddy as middleware
- Loading branch information
Showing
32 changed files
with
2,361 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Build container and validate lint/tests | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
lint-and-tests: | ||
name: Validate Go code linting | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
- name: tests | ||
run: go test -v -race ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Build and validate go-esi as plugins | ||
|
||
on: | ||
- pull_request | ||
|
||
jobs: | ||
build-caddy-validator: | ||
name: Check that go-esi build as caddy module | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Add domain.com host to /etc/hosts | ||
run: | | ||
sudo echo "127.0.0.1 domain.com" | sudo tee -a /etc/hosts | ||
- | ||
name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- | ||
name: Checkout code | ||
uses: actions/checkout@v2 | ||
- | ||
name: Install xcaddy | ||
run: go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest | ||
- | ||
name: Build go-esi as caddy module | ||
run: cd plugins/caddy && xcaddy build --with github.com/darkweak/go-esi/middleware/caddy=./ --with github.com/darkweak/go-esi@latest=../.. | ||
- | ||
name: Run Caddy tests | ||
run: cd plugins/caddy && go test -v ./... | ||
- | ||
name: Run detached caddy | ||
run: cd plugins/caddy && ./caddy run & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Build container and publish to docker hub | ||
|
||
on: | ||
create: | ||
tags: ["v*"] | ||
|
||
jobs: | ||
generate-artifacts: | ||
name: Deploy to goreleaser | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- | ||
name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v3 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
workdir: ./middleware/server | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
run: | ||
timeout: 30s | ||
issues-exit-code: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
before: | ||
hooks: | ||
- go mod download | ||
builds: | ||
- <<: &build_defaults | ||
ldflags: | ||
- -s -w | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- 386 | ||
- amd64 | ||
- arm | ||
- arm64 | ||
ignore: | ||
- goos: windows | ||
goarch: arm64 | ||
archives: | ||
- | ||
replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
format_overrides: | ||
- | ||
goos: windows | ||
format: zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.PHONY: lint run-caddy run-roadrunner | ||
|
||
lint: ## Run golangci-lint to ensure the code quality | ||
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint golangci-lint run | ||
|
||
run-caddy: ## Build caddy binary | ||
cd middleware/caddy && $(MAKE) build && $(MAKE) run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package go_esi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
package esi | ||
|
||
import "regexp" | ||
import ( | ||
"net/http" | ||
"regexp" | ||
) | ||
|
||
const escape = "escape" | ||
const escape = "<!--esi" | ||
|
||
var closeEscape = regexp.MustCompile("-->") | ||
var ( | ||
escapeRg = regexp.MustCompile("<!--esi") | ||
closeEscape = regexp.MustCompile("-->") | ||
) | ||
|
||
type escapeTag struct { | ||
*baseTag | ||
} | ||
|
||
func (e *escapeTag) process(b []byte, req *http.Request) ([]byte, int) { | ||
closeIdx := closeEscape.FindIndex(b) | ||
|
||
if closeIdx == nil { | ||
return nil, len(b) | ||
} | ||
|
||
e.length = closeIdx[1] | ||
b = b[:closeIdx[0]] | ||
|
||
return b, e.length | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.