From 4a0b7d71a9a5ccbfb88af29ad161c988d58cb429 Mon Sep 17 00:00:00 2001 From: SoXX Date: Fri, 28 Jun 2024 12:15:51 +0200 Subject: [PATCH] refactor: reorganized code structure Signed-off-by: SoXX --- internal/postgres/relationships_test.go | 8 ++--- internal/postgres/user.go | 41 +++++-------------------- internal/postgres/user_test.go | 18 +++++------ pkg/database/database.go | 7 +++++ pkg/database/postgres/postgres.go | 14 ++++----- pkg/database/postgres/postgres_test.go | 28 ++++++++--------- pkg/database/tagalias.go | 7 +++-- pkg/database/taggroup.go | 7 +++-- pkg/database/user.go | 36 +++++++++++++--------- test/helper.go | 17 +++++----- 10 files changed, 89 insertions(+), 94 deletions(-) diff --git a/internal/postgres/relationships_test.go b/internal/postgres/relationships_test.go index dec686d..dd67e2a 100644 --- a/internal/postgres/relationships_test.go +++ b/internal/postgres/relationships_test.go @@ -133,11 +133,11 @@ func TestCheckUserToPostLink(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := CheckReferenceBetweenUserAndPost(tt.args.ctx, tt.args.db, tt.args.anthroveUserID, tt.args.anthrovePostID) if (err != nil) != tt.wantErr { - t.Errorf("CheckReferenceBetweenUserAndPost() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CheckIfUserHasPostAsFavorite() error = %v, wantErr %v", err, tt.wantErr) return } if got != tt.want { - t.Errorf("CheckReferenceBetweenUserAndPost() got = %v, want %v", got, tt.want) + t.Errorf("CheckIfUserHasPostAsFavorite() got = %v, want %v", got, tt.want) } }) } @@ -266,11 +266,11 @@ func TestCheckUserToPostLinkWithNoData(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := CheckReferenceBetweenUserAndPost(tt.args.ctx, tt.args.db, tt.args.anthroveUserID, tt.args.anthrovePostID) if (err != nil) != tt.wantErr { - t.Errorf("CheckReferenceBetweenUserAndPost() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CheckIfUserHasPostAsFavorite() error = %v, wantErr %v", err, tt.wantErr) return } if got != tt.want { - t.Errorf("CheckReferenceBetweenUserAndPost() got = %v, want %v", got, tt.want) + t.Errorf("CheckIfUserHasPostAsFavorite() got = %v, want %v", got, tt.want) } }) } diff --git a/internal/postgres/user.go b/internal/postgres/user.go index b5c0ee3..8e8b2d7 100644 --- a/internal/postgres/user.go +++ b/internal/postgres/user.go @@ -169,9 +169,8 @@ func GetUserSourceLinks(ctx context.Context, db *gorm.DB, anthroveUserID models. return userSourceMap, nil } -func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (map[string]models.UserSource, error) { - var userSources []models.UserSource - userSourceMap := make(map[string]models.UserSource) +func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (*models.UserSource, error) { + var userSource *models.UserSource if anthroveUserID == "" { return nil, &otterError.EntityValidationFailed{Reason: otterError.AnthroveUserIDIsEmpty} @@ -189,7 +188,7 @@ func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID mo return nil, &otterError.EntityValidationFailed{Reason: "sourceID needs to be 25 characters long"} } - result := db.WithContext(ctx).Model(&models.UserSource{}).InnerJoins("Source", db.Where("id = ?", sourceID)).Where("user_id = ?", string(anthroveUserID)).First(&userSources) + result := db.WithContext(ctx).Model(&models.UserSource{}).InnerJoins("Source", db.Where("id = ?", sourceID)).Where("user_id = ?", string(anthroveUserID)).First(userSource) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { return nil, &otterError.NoDataFound{} @@ -197,38 +196,16 @@ func GetUserSourceBySourceID(ctx context.Context, db *gorm.DB, anthroveUserID mo return nil, result.Error } - for _, userSource := range userSources { - var source models.Source - result = db.WithContext(ctx).Model(&models.Source{}).Where("id = ?", userSource.SourceID).First(&source) - if result.Error != nil { - if errors.Is(result.Error, gorm.ErrRecordNotFound) { - return nil, &otterError.NoDataFound{} - } - return nil, result.Error - } - - userSourceMap[source.DisplayName] = models.UserSource{ - UserID: userSource.AccountID, - AccountUsername: userSource.AccountUsername, - Source: models.Source{ - DisplayName: source.DisplayName, - Domain: source.Domain, - Icon: source.Icon, - }, - } - } - log.WithFields(log.Fields{ "anthrove_user_id": anthroveUserID, "source_id": sourceID, }).Trace("database: got specified user source link") - return userSourceMap, nil + return userSource, nil } -func GetAllAnthroveUserIDs(ctx context.Context, db *gorm.DB) ([]models.AnthroveUserID, error) { +func GetAllUsers(ctx context.Context, db *gorm.DB) ([]models.User, error) { var users []models.User - var userIDs []models.AnthroveUserID result := db.WithContext(ctx).Model(&models.User{}).Find(&users) if result.Error != nil { @@ -238,15 +215,11 @@ func GetAllAnthroveUserIDs(ctx context.Context, db *gorm.DB) ([]models.AnthroveU return nil, result.Error } - for _, user := range users { - userIDs = append(userIDs, user.ID) - } - log.WithFields(log.Fields{ - "anthrove_user_id_count": len(userIDs), + "anthrove_user_id_count": len(users), }).Trace("database: got all anthrove user IDs") - return userIDs, nil + return users, nil } func GetUserFavoriteWithPagination(ctx context.Context, db *gorm.DB, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) { diff --git a/internal/postgres/user_test.go b/internal/postgres/user_test.go index b146d52..c4efa00 100644 --- a/internal/postgres/user_test.go +++ b/internal/postgres/user_test.go @@ -244,13 +244,13 @@ func TestGetAllAnthroveUserIDs(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := GetAllAnthroveUserIDs(tt.args.ctx, tt.args.db) + got, err := GetAllUsers(tt.args.ctx, tt.args.db) if (err != nil) != tt.wantErr { - t.Errorf("GetAllAnthroveUserIDs() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllUsers() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetAllAnthroveUserIDs() got = %v, want %v", got, tt.want) + t.Errorf("GetAllUsers() got = %v, want %v", got, tt.want) } }) } @@ -558,11 +558,11 @@ func TestGetUserFavoriteNodeWithPagination(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := GetUserFavoriteWithPagination(tt.args.ctx, tt.args.db, tt.args.anthroveUserID, tt.args.skip, tt.args.limit) if (err != nil) != tt.wantErr { - t.Errorf("GetUserFavoriteWithPagination() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllUserFavoritesWithPagination() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetUserFavoriteWithPagination() got = %v, want %v", got, tt.want) + t.Errorf("GetAllUserFavoritesWithPagination() got = %v, want %v", got, tt.want) } }) } @@ -798,11 +798,11 @@ func TestGetUserSourceLinks(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := GetUserSourceLinks(tt.args.ctx, tt.args.db, tt.args.anthroveUserID) if (err != nil) != tt.wantErr { - t.Errorf("GetUserSourceLinks() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllUserSources() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetUserSourceLinks() got = %v, want %v", got, tt.want) + t.Errorf("GetAllUserSources() got = %v, want %v", got, tt.want) } }) } @@ -930,11 +930,11 @@ func TestGetUserTagNodeWitRelationToFavedPosts(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := GetUserTagWitRelationToFavedPosts(tt.args.ctx, tt.args.db, tt.args.anthroveUserID) if (err != nil) != tt.wantErr { - t.Errorf("GetUserTagWitRelationToFavedPosts() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllTagsFromUser() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetUserTagWitRelationToFavedPosts() got = %v, want %v", got, tt.want) + t.Errorf("GetAllTagsFromUser() got = %v, want %v", got, tt.want) } }) } diff --git a/pkg/database/database.go b/pkg/database/database.go index 0cd0777..7b1aef2 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -10,8 +10,15 @@ type OtterSpace interface { // Connect establishes a connection to the database. Connect(ctx context.Context, config models.DatabaseConfig) error + // User contains all function that are needed to manage the AnthroveUser User + + // Source contains all function that are needed to manage the Source Source + + // TagAlias contains all function that are needed to manage the TagAlias TagAlias + + // TagGroup contains all function that are needed to manage the TagGroup TagGroup } diff --git a/pkg/database/postgres/postgres.go b/pkg/database/postgres/postgres.go index 714438a..da69ba8 100644 --- a/pkg/database/postgres/postgres.go +++ b/pkg/database/postgres/postgres.go @@ -97,7 +97,7 @@ func (p *postgresqlConnection) CreateReferenceBetweenUserAndPost(ctx context.Con return postgres.CreateReferenceBetweenUserAndPost(ctx, p.db, anthroveUserID, anthrovePostID) } -func (p *postgresqlConnection) CheckReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) (bool, error) { +func (p *postgresqlConnection) CheckIfUserHasPostAsFavorite(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) (bool, error) { return postgres.CheckReferenceBetweenUserAndPost(ctx, p.db, anthroveUserID, anthrovePostID) } @@ -117,23 +117,23 @@ func (p *postgresqlConnection) GetUserFavoritesCount(ctx context.Context, anthro return postgres.GetUserFavoritesCount(ctx, p.db, anthroveUserID) } -func (p *postgresqlConnection) GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.UserSource, error) { +func (p *postgresqlConnection) GetAllUserSources(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.UserSource, error) { return postgres.GetUserSourceLinks(ctx, p.db, anthroveUserID) } -func (p *postgresqlConnection) GetUserSourceBySourceID(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (map[string]models.UserSource, error) { +func (p *postgresqlConnection) GetUserSourceBySourceID(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (*models.UserSource, error) { return postgres.GetUserSourceBySourceID(ctx, p.db, anthroveUserID, sourceID) } -func (p *postgresqlConnection) GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) { - return postgres.GetAllAnthroveUserIDs(ctx, p.db) +func (p *postgresqlConnection) GetAllUser(ctx context.Context) ([]models.User, error) { + return postgres.GetAllUsers(ctx, p.db) } -func (p *postgresqlConnection) GetUserFavoriteWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) { +func (p *postgresqlConnection) GetAllUserFavoritesWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) { return postgres.GetUserFavoriteWithPagination(ctx, p.db, anthroveUserID, skip, limit) } -func (p *postgresqlConnection) GetUserTagWitRelationToFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) { +func (p *postgresqlConnection) GetAllTagsFromUser(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) { return postgres.GetUserTagWitRelationToFavedPosts(ctx, p.db, anthroveUserID) } diff --git a/pkg/database/postgres/postgres_test.go b/pkg/database/postgres/postgres_test.go index 721752a..bf7159f 100644 --- a/pkg/database/postgres/postgres_test.go +++ b/pkg/database/postgres/postgres_test.go @@ -714,13 +714,13 @@ func Test_postgresqlConnection_CheckReferenceBetweenUserAndPost(t *testing.T) { db: gormDB, debug: true, } - got, err := p.CheckReferenceBetweenUserAndPost(tt.args.ctx, tt.args.anthroveUserID, tt.args.anthrovePostID) + got, err := p.CheckIfUserFavouritedPost(tt.args.ctx, tt.args.anthroveUserID, tt.args.anthrovePostID) if (err != nil) != tt.wantErr { - t.Errorf("CheckReferenceBetweenUserAndPost() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("CheckIfUserHasPostAsFavorite() error = %v, wantErr %v", err, tt.wantErr) return } if got != tt.want { - t.Errorf("CheckReferenceBetweenUserAndPost() got = %v, want %v", got, tt.want) + t.Errorf("CheckIfUserHasPostAsFavorite() got = %v, want %v", got, tt.want) } }) } @@ -1207,13 +1207,13 @@ func Test_postgresqlConnection_GetUserSourceLinks(t *testing.T) { db: gormDB, debug: true, } - got, err := p.GetUserSourceLinks(tt.args.ctx, tt.args.anthroveUserID) + got, err := p.GetAllUserSources(tt.args.ctx, tt.args.anthroveUserID) if (err != nil) != tt.wantErr { - t.Errorf("GetUserSourceLinks() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllUserSources() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetUserSourceLinks() got = %v, want %v", got, tt.want) + t.Errorf("GetAllUserSources() got = %v, want %v", got, tt.want) } }) } @@ -1405,11 +1405,11 @@ func Test_postgresqlConnection_GetAllAnthroveUserIDs(t *testing.T) { } got, err := p.GetAllAnthroveUserIDs(tt.args.ctx) if (err != nil) != tt.wantErr { - t.Errorf("GetAllAnthroveUserIDs() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllUsers() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetAllAnthroveUserIDs() got = %v, want %v", got, tt.want) + t.Errorf("GetAllUsers() got = %v, want %v", got, tt.want) } }) } @@ -1540,13 +1540,13 @@ func Test_postgresqlConnection_GetUserFavoriteWithPagination(t *testing.T) { db: gormDB, debug: true, } - got, err := p.GetUserFavoriteWithPagination(tt.args.ctx, tt.args.anthroveUserID, tt.args.skip, tt.args.limit) + got, err := p.GetAllUserFavoritesWithPagination(tt.args.ctx, tt.args.anthroveUserID, tt.args.skip, tt.args.limit) if (err != nil) != tt.wantErr { - t.Errorf("GetUserFavoriteWithPagination() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllUserFavoritesWithPagination() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetUserFavoriteWithPagination() got = %v, want %v", got, tt.want) + t.Errorf("GetAllUserFavoritesWithPagination() got = %v, want %v", got, tt.want) } }) } @@ -1654,13 +1654,13 @@ func Test_postgresqlConnection_GetUserTagWitRelationToFavedPosts(t *testing.T) { db: gormDB, debug: true, } - got, err := p.GetUserTagWitRelationToFavedPosts(tt.args.ctx, tt.args.anthroveUserID) + got, err := p.GetAllTagsFromUser(tt.args.ctx, tt.args.anthroveUserID) if (err != nil) != tt.wantErr { - t.Errorf("GetUserTagWitRelationToFavedPosts() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("GetAllTagsFromUser() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetUserTagWitRelationToFavedPosts() got = %v, want %v", got, tt.want) + t.Errorf("GetAllTagsFromUser() got = %v, want %v", got, tt.want) } }) } diff --git a/pkg/database/tagalias.go b/pkg/database/tagalias.go index ef5f2e5..30171d4 100644 --- a/pkg/database/tagalias.go +++ b/pkg/database/tagalias.go @@ -7,8 +7,11 @@ import ( ) type TagAlias interface { - GetAllTagAlias(ctx context.Context) ([]models.TagAlias, error) - GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error) CreateTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName, tagID models.AnthroveTagID) error + + GetAllTagAlias(ctx context.Context) ([]models.TagAlias, error) + + GetAllTagAliasByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagAlias, error) + DeleteTagAlias(ctx context.Context, tagAliasName models.AnthroveTagAliasName) error } diff --git a/pkg/database/taggroup.go b/pkg/database/taggroup.go index db3918a..594cd1e 100644 --- a/pkg/database/taggroup.go +++ b/pkg/database/taggroup.go @@ -7,8 +7,11 @@ import ( ) type TagGroup interface { - GetAllTagGroup(ctx context.Context) ([]models.TagGroup, error) - GetAllTagGroupByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagGroup, error) CreateTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName, tagID models.AnthroveTagID) + + GetAllTagGroup(ctx context.Context) ([]models.TagGroup, error) + + GetAllTagGroupByTag(ctx context.Context, tagID models.AnthroveTagID) ([]models.TagGroup, error) + DeleteTagGroup(ctx context.Context, tagGroupName models.AnthroveTagGroupName) error } diff --git a/pkg/database/user.go b/pkg/database/user.go index d90ca51..e7be12e 100644 --- a/pkg/database/user.go +++ b/pkg/database/user.go @@ -7,28 +7,36 @@ import ( ) type User interface { - // GetAllAnthroveUserIDs retrieves all Anthrove user IDs. - GetAllAnthroveUserIDs(ctx context.Context) ([]models.AnthroveUserID, error) // CreateUserWithRelationToSource adds a user with a relation to a source. CreateUserWithRelationToSource(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, accountId string, accountUsername string) error + // CreateReferenceBetweenUserAndPost links a user with a post. CreateReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, anthrovePostID models.AnthrovePostID) error - // CheckReferenceBetweenUserAndPost checks if a user-post link exists. - CheckReferenceBetweenUserAndPost(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID models.AnthrovePostID) (bool, error) - // GetUserFavoritesCount retrieves the count of a user's favorites. - GetUserFavoritesCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) - // GetUserSourceLinks retrieves the source links of a user. - GetUserSourceLinks(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.UserSource, error) - // GetUserSourceBySourceID retrieves a specified source link of a user. - GetUserSourceBySourceID(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (map[string]models.UserSource, error) - // GetUserFavoriteWithPagination retrieves a user's favorite posts with pagination. - GetUserFavoriteWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) - // GetUserTagWitRelationToFavedPosts retrieves a user's tags through their favorited posts. - GetUserTagWitRelationToFavedPosts(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) UpdateUserSourceScrapeTimeInterval(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, scrapeTime models.AnthroveScrapeTimeInterval) error + UpdateUserSourceLastScrapeTime(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, lastScrapeTime models.AnthroveUserLastScrapeTime) error UpdateUserSourceValidation(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID, valid bool) error + + GetAllUser(ctx context.Context) ([]models.User, error) + + // GetUserFavoritesCount retrieves the count of a user's favorites. + GetUserFavoritesCount(ctx context.Context, anthroveUserID models.AnthroveUserID) (int64, error) + + // GetAllUserSources retrieves the source links of a user. + GetAllUserSources(ctx context.Context, anthroveUserID models.AnthroveUserID) (map[string]models.UserSource, error) + + // GetUserSourceBySourceID retrieves a specified source link of a user. + GetUserSourceBySourceID(ctx context.Context, anthroveUserID models.AnthroveUserID, sourceID models.AnthroveSourceID) (*models.UserSource, error) + + // GetAllUserFavoritesWithPagination retrieves a user's favorite posts with pagination. + GetAllUserFavoritesWithPagination(ctx context.Context, anthroveUserID models.AnthroveUserID, skip int, limit int) (*models.FavoriteList, error) + + // GetAllTagsFromUser retrieves a user's tags through their favorite posts. + GetAllTagsFromUser(ctx context.Context, anthroveUserID models.AnthroveUserID) ([]models.TagsWithFrequency, error) + + // CheckIfUserHasPostAsFavorite checks if a user-post link exists. + CheckIfUserHasPostAsFavorite(ctx context.Context, anthroveUserID models.AnthroveUserID, sourcePostID models.AnthrovePostID) (bool, error) } diff --git a/test/helper.go b/test/helper.go index 93a185e..ce571d2 100644 --- a/test/helper.go +++ b/test/helper.go @@ -3,15 +3,16 @@ package test import ( "context" "database/sql" + "net/url" + "strconv" + "strings" + "git.dragse.it/anthrove/otter-space-sdk/pkg/models" migrate "github.com/rubenv/sql-migrate" postgrescontainer "github.com/testcontainers/testcontainers-go/modules/postgres" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" - "net/url" - "strconv" - "strings" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" @@ -88,12 +89,12 @@ func DatabaseModesFromConnectionString(ctx context.Context, pgContainer *postgre return nil, err } - url, err := url.Parse(connectionString) + connectionStringUrl, err := url.Parse(connectionString) if err != nil { return nil, err } - split := strings.Split(url.Host, ":") + split := strings.Split(connectionStringUrl.Host, ":") host := split[0] port, err := strconv.Atoi(split[1]) @@ -101,10 +102,10 @@ func DatabaseModesFromConnectionString(ctx context.Context, pgContainer *postgre return nil, err } - database := strings.TrimPrefix(url.Path, "/") + database := strings.TrimPrefix(connectionStringUrl.Path, "/") - username := url.User.Username() - password, _ := url.User.Password() + username := connectionStringUrl.User.Username() + password, _ := connectionStringUrl.User.Password() return &models.DatabaseConfig{ Endpoint: host,