fix: implement various deepsource suggestions

This commit is contained in:
Vikram Rangnekar
2020-06-15 10:16:47 -04:00
parent 06214a3850
commit dd4accfdd2
26 changed files with 76 additions and 86 deletions

View File

@ -47,17 +47,17 @@ func SimpleHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
ctx := r.Context()
userIDProvider := r.Header.Get("X-User-ID-Provider")
if len(userIDProvider) != 0 {
if userIDProvider != "" {
ctx = context.WithValue(ctx, core.UserIDProviderKey, userIDProvider)
}
userID := r.Header.Get("X-User-ID")
if len(userID) != 0 {
if userID != "" {
ctx = context.WithValue(ctx, core.UserIDKey, userID)
}
userRole := r.Header.Get("X-User-Role")
if len(userRole) != 0 {
if userRole != "" {
ctx = context.WithValue(ctx, core.UserRoleKey, userRole)
}
@ -68,11 +68,11 @@ func SimpleHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
func HeaderHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
hdr := ac.Header
if len(hdr.Name) == 0 {
if hdr.Name == "" {
return nil, fmt.Errorf("auth '%s': no header.name defined", ac.Name)
}
if !hdr.Exists && len(hdr.Value) == 0 {
if !hdr.Exists && hdr.Value == "" {
return nil, fmt.Errorf("auth '%s': no header.value defined", ac.Name)
}
@ -82,7 +82,7 @@ func HeaderHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
switch {
case hdr.Exists:
fo1 = (len(value) == 0)
fo1 = (value == "")
default:
fo1 = (value != hdr.Value)

View File

@ -44,10 +44,10 @@ func JwtHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
publicKeyFile := ac.JWT.PubKeyFile
switch {
case len(secret) != 0:
case secret != "":
key = []byte(secret)
case len(publicKeyFile) != 0:
case publicKeyFile != "":
kd, err := ioutil.ReadFile(publicKeyFile)
if err != nil {
return nil, err
@ -74,7 +74,7 @@ func JwtHandler(ac *Auth, next http.Handler) (http.HandlerFunc, error) {
var tok string
if len(cookie) != 0 {
if cookie != "" {
ck, err := r.Cookie(cookie)
if err != nil {
next.ServeHTTP(w, r)

View File

@ -165,7 +165,7 @@ func railsAuth(ac *Auth) (*rails.Auth, error) {
}
version := ac.Rails.Version
if len(version) == 0 {
if version == "" {
return nil, errors.New("no auth.rails.version defined")
}

View File

@ -199,7 +199,7 @@ func (m *Migrator) LoadMigrations(path string) error {
for _, v := range strings.Split(upSQL, "\n") {
// Only account for regular single line comment, empty line and space/comment combination
cleanString := strings.TrimSpace(v)
if len(cleanString) != 0 &&
if cleanString != "" &&
!strings.HasPrefix(cleanString, "--") {
containsSQL = true
break