You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: connstring.go
    path of file: ./repos/mongo-go-driver/x/mongo/driver/connstring
    
    the code of the file until where you have to start completion: // Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package connstring // import "go.mongodb.org/mongo-driver/x/mongo/driver/connstring"

impo
    
func (u *ConnString) setDefaultAuthParams(dbName string) error {
	// We do this check here rather than in validateAuth because this function is called as part of parsing and sets
	// the value of AuthSource if authentication is enabled.
	if u.AuthSourceSet && u.AuthSource == "" {
		return errors.New("authSource must be non-empty when supplied in a URI")
	}

	switch strings.ToLower(u.AuthMechanism) {
	case "plain":
		if u.AuthSource == "" {
			u.AuthSource = dbName
			if u.AuthSource == "" {
				u.AuthSource = "$external"
			}
		}
	case "gssapi":
		if u.AuthMechanismProperties == nil {
			u.AuthMechanismProperties = map[string]string{
				"SERVICE_NAME": "mongodb",
			}
		} else if v, ok := u.AuthMechanismProperties["SERVICE_NAME"]; !ok || v == "" {
			u.AuthMechanismProperties["SERVICE_NAME"] = "mongodb"
		}
		fallthrough
	case "mongodb-aws", "mongodb-x509":
		if u.AuthSource == "" {
			u.AuthSource = "$external"
		} else if u.AuthSource != "$external" {
			return fmt.Errorf("auth source must be $external")
		}
	case "mongodb-cr":
		fallthrough
	case "scram-sha-1":
		fallthrough
	case "scram-sha-256":
		if u.AuthSource == "" {
			u.AuthSource = dbName
			if u.AuthSource == "" {
				u.AuthSource = "admin"
			}
		}
	case "":
		// Only set auth source if there is a request for authentication via non-empty credentials.
		if u.AuthSource == "" && (u.AuthMechanismProperties != nil || u.Username != "" || u.PasswordSet) {
			u.AuthSource = dbName
			if u.AuthSource == "" {
				u.AuthSource = "admin"
			}
		}
	default:
		return fmt.Errorf("invalid auth mechanism")
	}
	return nil
}