From f952383838394986488ba2842e1bba180d292bc6 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Sat, 13 Feb 2021 08:02:05 +0000 Subject: [PATCH] - Remove unnecessary wrapping of function call - Remove unnecessary use of slice - Replace use of HTTP codes with constants --- handler/api/repos/encrypt/encrypt.go | 2 +- handler/web/login.go | 4 ++-- metric/handler.go | 4 ++-- plugin/registry/encrypted.go | 2 +- plugin/secret/encrypted.go | 2 +- server/server.go | 12 +++--------- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/handler/api/repos/encrypt/encrypt.go b/handler/api/repos/encrypt/encrypt.go index 9c95e990..3ad156a7 100644 --- a/handler/api/repos/encrypt/encrypt.go +++ b/handler/api/repos/encrypt/encrypt.go @@ -71,7 +71,7 @@ func Handler(repos core.RepositoryStore) http.HandlerFunc { } func encrypt(plaintext, key []byte) (ciphertext []byte, err error) { - block, err := aes.NewCipher(key[:]) + block, err := aes.NewCipher(key) if err != nil { return nil, err } diff --git a/handler/web/login.go b/handler/web/login.go index 89698330..bbf5a7fb 100644 --- a/handler/web/login.go +++ b/handler/web/login.go @@ -172,7 +172,7 @@ func HandleLogin( logger.Debugf("authentication successful") session.Create(w, user) - http.Redirect(w, r, "/", 303) + http.Redirect(w, r, "/", http.StatusSeeOther) } } @@ -192,7 +192,7 @@ func synchronize(ctx context.Context, syncer core.Syncer, user *core.User) { } func writeLoginError(w http.ResponseWriter, r *http.Request, err error) { - http.Redirect(w, r, "/login/error?message="+err.Error(), 303) + http.Redirect(w, r, "/login/error?message="+err.Error(), http.StatusSeeOther) } func writeLoginErrorStr(w http.ResponseWriter, r *http.Request, s string) { diff --git a/metric/handler.go b/metric/handler.go index 724e3b42..6f186aa1 100644 --- a/metric/handler.go +++ b/metric/handler.go @@ -44,9 +44,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { user, _ := s.session.Get(r) switch { case !s.anonymous && user == nil: - http.Error(w, errInvalidToken.Error(), 401) + http.Error(w, errInvalidToken.Error(), http.StatusUnauthorized) case !s.anonymous && !user.Admin && !user.Machine: - http.Error(w, errAccessDenied.Error(), 403) + http.Error(w, errAccessDenied.Error(), http.StatusForbidden) default: s.metrics.ServeHTTP(w, r) } diff --git a/plugin/registry/encrypted.go b/plugin/registry/encrypted.go index 34fce12d..ab204411 100644 --- a/plugin/registry/encrypted.go +++ b/plugin/registry/encrypted.go @@ -99,7 +99,7 @@ func getEncrypted(manifest *yaml.Manifest, match string) (data string, ok bool) } func decrypt(ciphertext []byte, key []byte) (plaintext []byte, err error) { - block, err := aes.NewCipher(key[:]) + block, err := aes.NewCipher(key) if err != nil { return nil, err } diff --git a/plugin/secret/encrypted.go b/plugin/secret/encrypted.go index 5270fa36..fb65feae 100644 --- a/plugin/secret/encrypted.go +++ b/plugin/secret/encrypted.go @@ -97,7 +97,7 @@ func getEncrypted(manifest *yaml.Manifest, match string) (data string, ok bool) } func decrypt(ciphertext []byte, key []byte) (plaintext []byte, err error) { - block, err := aes.NewCipher(key[:]) + block, err := aes.NewCipher(key) if err != nil { return nil, err } diff --git a/server/server.go b/server/server.go index 49a8c7eb..25f91a5b 100644 --- a/server/server.go +++ b/server/server.go @@ -58,9 +58,7 @@ func (s Server) listenAndServe(ctx context.Context) error { return s1.Shutdown(ctx) } }) - g.Go(func() error { - return s1.ListenAndServe() - }) + g.Go(s1.ListenAndServe) return g.Wait() } @@ -74,9 +72,7 @@ func (s Server) listenAndServeTLS(ctx context.Context) error { Addr: ":https", Handler: s.Handler, } - g.Go(func() error { - return s1.ListenAndServe() - }) + g.Go(s1.ListenAndServe) g.Go(func() error { return s2.ListenAndServeTLS( s.Cert, @@ -117,9 +113,7 @@ func (s Server) listenAndServeAcme(ctx context.Context) error { MinVersion: tls.VersionTLS12, }, } - g.Go(func() error { - return s1.ListenAndServe() - }) + g.Go(s1.ListenAndServe) g.Go(func() error { return s2.ListenAndServeTLS("", "") })