Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ permissions:
contents: read

jobs:
golangci:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: 📦 Install Mise
run: |
curl https://mise.run | sh
mise install

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.4
- name: lint
run: mise lint
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Install Go
uses: actions/setup-go@v5
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
dist/*
vendor
bin/
43 changes: 43 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[tools]
go = "1.26"
"go:github.com/daixiang0/gci" = "latest"
"ubi:golangci/golangci-lint" = "2.10"
"ubi:goreleaser/goreleaser" = "2.14"

[env]
CGO_ENABLED=0
LGFLAGS="-extldflags '-static'"

[tasks.vendor]
description = "Vendor resets the main module's vendor directory to include all packages needed to build the application"
run = "go mod vendor"

[tasks.tidy]
description = "Tidy makes sure go.mod matches the source code in the module"
run = "go mod tidy"

[tasks.build]
description = "Build the application"
run = '''
go build -o bin/proxy-app -ldflags=${LDFLAGS} github.com/skpr/proxy-app
'''
depends = ["vendor"]

[tasks."lint"]
description = "Linting automatically checks code for errors and style issues"
run = "golangci-lint run"

[tasks.test]
description = "Checks to verify code correctness"
run = "go test -cover ./..."
depends = ["vendor"]

[tasks.release]
description = "Release the command line interface"
run = "goreleaser release"
depends = ["vendor"]

[tasks.snapshot]
description = "Create a snapshot release for local testing"
run = "goreleaser release --snapshot --clean"
depends = ["vendor"]
6 changes: 0 additions & 6 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/skpr/proxy-app

go 1.25
go 1.26

require (
github.com/skpr/go-config v0.0.0-20210803015120-ef4cd8061d76
Expand Down
11 changes: 5 additions & 6 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,22 @@ func Run(params RunParams, config config.File) error {

proxy := httputil.NewSingleHostReverseProxy(endpoint)

d := proxy.Director

// Don't recompute this for every request...
basicAuthHeader := ""
if params.Username != "" {
basicAuthHeader = fmt.Sprintf("Basic %s", basicAuth(params.Username, params.Password))
}

proxy.Director = func(r *http.Request) {
d(r) // call default director
proxy.Rewrite = func(r *httputil.ProxyRequest) {
r.SetURL(endpoint)
r.SetXForwarded()

if basicAuthHeader != "" {
r.Header.Set("Authorization", basicAuthHeader)
r.Out.Header.Set("Authorization", basicAuthHeader)
}

if params.TrimPathPrefix != "" {
r.URL.Path = strings.TrimPrefix(r.URL.Path, params.TrimPathPrefix)
r.Out.URL.Path = strings.TrimPrefix(r.Out.URL.Path, params.TrimPathPrefix)
}
}

Expand Down