Remove fmt.Println and add Zerolog logging system
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m2s

This commit is contained in:
2024-11-11 20:35:17 +01:00
parent 4ae6aa7a90
commit 5e4cea0bb3
11 changed files with 88 additions and 55 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
@@ -185,7 +186,7 @@ func (s MongoDBStorage) CreateAccount(account Account) error {
func (s MongoDBStorage) UpdateAccount(account Account) error {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
if _, err := collection.ReplaceOne(context.TODO(), bson.M{"_id": account.ID}, account); err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return err
}
@@ -193,6 +194,6 @@ func (s MongoDBStorage) UpdateAccount(account Account) error {
}
func (s MongoDBStorage) Migrate() error {
fmt.Println("no migration")
log.Error().Msg("no migration")
return nil
}

View File

@@ -13,6 +13,7 @@ import (
"ariga.io/atlas/sql/schema"
"github.com/lib/pq"
_ "github.com/lib/pq"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
@@ -38,12 +39,12 @@ func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) {
psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", host, portInt, user, password, dbname, sslmode)
db, err := sql.Open("postgres", psqlconn)
if err != nil {
fmt.Println("error", err)
log.Error().Err(err).Msg("error opening postgresql connection")
return PostgresqlStorage{}, fmt.Errorf("connection to postgresql failed")
}
err = db.Ping()
if err != nil {
fmt.Println(err)
log.Error().Err(err).Msg("")
return PostgresqlStorage{}, fmt.Errorf("connection to postgresql database failed")
}
return PostgresqlStorage{
@@ -129,7 +130,7 @@ func (psql PostgresqlStorage) LocalAuthentication(namespace string, username *st
req += fmt.Sprintf(` AND phone_number = '%s'`, *phone_number)
}
req += ";"
fmt.Println(req)
account.Authentication.Local = &LocalAuth{}
err := psql.DbConnection.QueryRow(req).Scan(
&account.ID,
@@ -145,22 +146,22 @@ func (psql PostgresqlStorage) LocalAuthentication(namespace string, username *st
}
err = json.Unmarshal(metadata, &account.Metadata)
if err != nil {
fmt.Println("one")
log.Error().Err(err).Msg("error unmarshalling account metadata")
return nil, err
}
err = json.Unmarshal(data, &account.Data)
if err != nil {
fmt.Println("two")
log.Error().Err(err).Msg("error unmarshalling account data")
return nil, err
}
err = json.Unmarshal(emailValidation, &account.Authentication.Local.EmailValidation)
if err != nil {
fmt.Println("three")
log.Error().Err(err).Msg("error unmarshalling email validation")
return nil, err
}
err = json.Unmarshal(phoneValidation, &account.Authentication.Local.PhoneNumberValidation)
if err != nil {
fmt.Println("four")
log.Error().Err(err).Msg("error unmarshalling phone validation")
return nil, err
}
return account, nil