Skip to content

Commit

Permalink
Add debug and upgrade to Go 1.19 (#10)
Browse files Browse the repository at this point in the history
* add debug mode with request logging
* upgrade to go 1.19
  • Loading branch information
pablo-ruth authored Aug 29, 2022
1 parent fd8eec0 commit d6b5ef3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.19

- name: Run Golang CI Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.33
version: latest

- name: Build
run: CGO_ENABLED=0 go build -ldflags="-extldflags '-static' -w -s" -o k8s-dashboard-auth-proxy
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.19

- name: Run Golang CI Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.33
version: latest

- name: Build
run: CGO_ENABLED=0 go build -ldflags="-extldflags '-static' -w -s" -o k8s-dashboard-auth-proxy
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ func main() {

// Define and parse flags
var loginURL, guestClusterName, proxyURL string
var debug bool
flag.StringVar(&loginURL, "login-url", "", "WCP login URL")
flag.StringVar(&guestClusterName, "guest-cluster-name", "", "Tanzu guest cluster name")
flag.StringVar(&proxyURL, "proxy-url", "http://127.0.0.1:9090/", "Dashboard URL to proxy")
flag.BoolVar(&debug, "debug", false, "Debug mode")
flag.Parse()

// Check that loginURL and guestClusterName are set
Expand All @@ -24,7 +26,7 @@ func main() {
}

// Server requests
err := proxy.Server(loginURL, guestClusterName, proxyURL)
err := proxy.Server(loginURL, guestClusterName, proxyURL, debug)
if err != nil {
fmt.Printf("failed to start proxy: %s", err)
os.Exit(1)
Expand Down
12 changes: 10 additions & 2 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import (
"net/http"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)

func Server(loginURL, guestClusterName, proxyURL string) error {
func Server(loginURL, guestClusterName, proxyURL string, debug bool) error {

// Remove timestamp from logs
log.SetFlags(0)

// Create router and register handlers
// Create router
r := chi.NewRouter()

// Enable request logging if debug is enabled
if debug {
r.Use(middleware.Logger)
}

// Add routes
r.HandleFunc("/*", proxyHandler(proxyURL))
r.Get("/login", loginGetHandler)
r.Post("/login", loginPostHandler(loginURL, guestClusterName))
Expand Down

0 comments on commit d6b5ef3

Please sign in to comment.