- Remove unnecessary wrapping of function call

- Remove unnecessary use of slice

- Replace use of HTTP codes with constants
This commit is contained in:
Shubhendra Singh Chauhan 2021-02-13 08:02:05 +00:00 committed by shubhendra
parent 6e6d591117
commit f952383838
No known key found for this signature in database
GPG key ID: 9AFEF5C98D542137
6 changed files with 10 additions and 16 deletions

View file

@ -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
}

View file

@ -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) {

View file

@ -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)
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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("", "")
})