From 6f4be12e8c925209d27ee6ae131ba48a5f9b1992 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 21 Jul 2024 19:43:30 +0200 Subject: [PATCH] ci: updated build and lint workflows (#152) --- .github/workflows/build.yml | 17 +++++++++++++++++ .github/workflows/lint.yml | 19 +++++++++++++++++++ cmd/root.go | 2 +- lib/user.go | 2 +- lib/webdav.go | 6 +++--- 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..617e4f8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: Build +on: + push: + tags: + - v* + branches: + - main + pull_request: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.22.x" + - run: go build . diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..26ad40e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,19 @@ +name: Lint +on: + push: + tags: + - v* + branches: + - main + pull_request: +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.22.x" + - uses: golangci/golangci-lint-action@v6 + with: + version: "v1.59" diff --git a/cmd/root.go b/cmd/root.go index 88ee4db..4c29c82 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -71,7 +71,7 @@ set WD_CERT.`, listener, err := net.Listen(lnet, laddr) sigc := make(chan os.Signal, 1) - signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM) + signal.Notify(sigc, os.Interrupt, syscall.SIGTERM) go func(c chan os.Signal) { // Wait for a SIGINT or SIGKILL: diff --git a/lib/user.go b/lib/user.go index 8b853a2..fc7000a 100755 --- a/lib/user.go +++ b/lib/user.go @@ -7,7 +7,7 @@ import ( "golang.org/x/net/webdav" ) -// Rule is a dissalow/allow rule. +// Rule is a disallow/allow rule. type Rule struct { Regex bool Allow bool diff --git a/lib/webdav.go b/lib/webdav.go index ce2743d..8545c15 100644 --- a/lib/webdav.go +++ b/lib/webdav.go @@ -77,19 +77,19 @@ func (c *Config) ServeHTTP(w http.ResponseWriter, r *http.Request) { username, password, ok := r.BasicAuth() zap.L().Info("login attempt", zap.String("username", username), zap.String("remote_address", r.RemoteAddr)) if !ok { - http.Error(w, "Not authorized", 401) + http.Error(w, "Not authorized", http.StatusUnauthorized) return } user, ok := c.Users[username] if !ok { - http.Error(w, "Not authorized", 401) + http.Error(w, "Not authorized", http.StatusUnauthorized) return } if !checkPassword(user.Password, password) { zap.L().Info("invalid password", zap.String("username", username), zap.String("remote_address", r.RemoteAddr)) - http.Error(w, "Not authorized", 401) + http.Error(w, "Not authorized", http.StatusUnauthorized) return }