try doing magic with generics
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-11 14:48:08 +11:00
parent afec665759
commit 1a90963851
4 changed files with 205 additions and 165 deletions

View File

@@ -35,6 +35,11 @@ type UserSecret struct {
Permission
}
// This method allows us to use an interface to avoid adding duplicate entries to a []Secret
func (s Secret) GetId() int {
return s.SecretId
}
func (s *Secret) SaveSecret() (*Secret, error) {
var err error
@@ -141,7 +146,12 @@ func SecretsGetAllowed(s *Secret, userId int) ([]UserSecret, error) {
log.Println(debugPrint)
// Append the secrets to the query output, don't decrypt the secrets (we didn't SELECT them anyway)
secretResults = append(secretResults, r)
//secretResults = append(secretResults, r)
// Use generics and the GetID() method on the UserSecret struct
// to avoid adding this element to the results
// if there is already a secret with the same ID present
secretResults = utils.AppendIfNotExists(secretResults, r)
}
log.Printf("SecretsGetAllowed retrieved '%d' results\n", len(secretResults))
}