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
9 changes: 9 additions & 0 deletions bin/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if ! golangci-lint version &> /dev/null
then
echo "golangci-lint not found, installing it"
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
fi

golangci-lint run ./...
22 changes: 17 additions & 5 deletions domain/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package auth
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"

Expand All @@ -22,7 +22,11 @@ type handlers struct {

func (h *handlers) GetPing() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
if _, err := w.Write([]byte("ok")); err != nil {
log.Printf("failed to write to reponse writer: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
}

Expand All @@ -43,13 +47,17 @@ func (h *handlers) GetCurrentUser() http.HandlerFunc {
return
}

w.Write([]byte(u.Username))
if _, err := w.Write([]byte(u.Username)); err != nil {
log.Printf("failed to write to reponse writer: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
}

func (h *handlers) PostSignIn() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
log.Printf("failed to read request body: %v", err)
http.Error(w, "failed to read request body", http.StatusInternalServerError)
Expand All @@ -74,7 +82,11 @@ func (h *handlers) PostSignIn() http.HandlerFunc {
return
}

w.Write([]byte(u.Username))
if _, err := w.Write([]byte(u.Username)); err != nil {
log.Printf("failed to write to reponse writer: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}

}
}
Expand Down
7 changes: 6 additions & 1 deletion domain/users/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package users
import (
"context"
"encoding/json"
"log"
"net/http"

"github.com/admin-golang/admin/dataloader"
Expand Down Expand Up @@ -48,7 +49,11 @@ func (h *handlers) GetUsers() http.HandlerFunc {
return
}

w.Write(resp)
if _, err := w.Write(resp); err != nil {
log.Printf("failed to write to reponse writer: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/ctxutil/ctxutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"strings"
)

const AuthHeaderName = "Authorization"
type AuthHeaderNameType string

const AuthHeaderName AuthHeaderNameType = "Authorization"

func WithAuthHeader(ctx context.Context, header http.Header) context.Context {
return context.WithValue(ctx, AuthHeaderName, header.Get(AuthHeaderName))
return context.WithValue(ctx, AuthHeaderName, header.Get(string(AuthHeaderName)))
}

func AuthHeaderValueFromCtx(ctx context.Context) (string, error) {
Expand Down