Remove fmt.Prinln and add Zerolog logging system
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m51s
All checks were successful
Build and Push Docker Image / build_and_push (push) Successful in 1m51s
This commit is contained in:
@@ -2,8 +2,8 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@@ -77,15 +77,13 @@ func (s MongoDBStorage) GetEvents(namespaces []string) (events []Event, err erro
|
||||
if len(namespaces) == 0 {
|
||||
cur, err = collection.Find(context.TODO(), bson.D{}, findOptions)
|
||||
if err != nil {
|
||||
fmt.Println("...")
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return events, err
|
||||
}
|
||||
} else {
|
||||
cur, err = collection.Find(context.TODO(), bson.M{"namespace": bson.M{"$in": namespaces}}, findOptions)
|
||||
if err != nil {
|
||||
fmt.Println("Error here")
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return events, err
|
||||
}
|
||||
}
|
||||
@@ -98,12 +96,6 @@ func (s MongoDBStorage) GetEvents(namespaces []string) (events []Event, err erro
|
||||
return events, err
|
||||
}
|
||||
|
||||
// fmt.Println(elem)
|
||||
|
||||
// bsonBytes, _ := bson.Marshal(elem)
|
||||
// fmt.Println(string(bsonBytes))
|
||||
// bson.Unmarshal(bsonBytes, &event)
|
||||
|
||||
events = append(events, event)
|
||||
|
||||
}
|
||||
@@ -147,7 +139,7 @@ func (s MongoDBStorage) UpdateSubscription(eventid string, subscriber string, de
|
||||
func (s MongoDBStorage) UpdateEvent(event Event) error {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["events"])
|
||||
if _, err := collection.ReplaceOne(context.TODO(), bson.M{"_id": event.ID}, event); err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"ariga.io/atlas/sql/postgres"
|
||||
"ariga.io/atlas/sql/schema"
|
||||
"github.com/lib/pq"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -38,12 +39,12 @@ func NewPostgresqlStorage(cfg *viper.Viper) (PostgresqlStorage, error) {
|
||||
user, password, dbname, sslmode, timezone)
|
||||
db, err := sql.Open("postgres", psqlconn)
|
||||
if err != nil {
|
||||
fmt.Println("error", err)
|
||||
log.Error().Err(err).Msg("erroropening postgresql connection")
|
||||
return PostgresqlStorage{}, fmt.Errorf("connection to postgresql failed")
|
||||
}
|
||||
err = db.Ping()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("error trying to reach postgresql server")
|
||||
return PostgresqlStorage{}, fmt.Errorf("connection to postgresql database failed")
|
||||
}
|
||||
return PostgresqlStorage{
|
||||
@@ -413,7 +414,7 @@ func (psql PostgresqlStorage) UpdateSubscription(eventid string, subscriber stri
|
||||
subscriber,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return err
|
||||
}
|
||||
eventQuery := fmt.Sprintf(`
|
||||
@@ -423,7 +424,7 @@ func (psql PostgresqlStorage) UpdateSubscription(eventid string, subscriber stri
|
||||
`, psql.Tables["event"])
|
||||
deletedSubscriptions, err := json.Marshal(deletesubscription)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(
|
||||
@@ -432,7 +433,7 @@ func (psql PostgresqlStorage) UpdateSubscription(eventid string, subscriber stri
|
||||
eventid,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -482,7 +483,7 @@ func (psql PostgresqlStorage) GetSubscriber(subscriber string) ([]Subscription,
|
||||
subscriptionQuery := fmt.Sprintf("SELECT id, event_id, subscriber, tags, created_at, data FROM %s WHERE subscriber = $1", psql.Tables["subscription"])
|
||||
rows, err := psql.DbConnection.Query(subscriptionQuery, subscriber)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
@@ -499,14 +500,14 @@ func (psql PostgresqlStorage) GetSubscriber(subscriber string) ([]Subscription,
|
||||
&dataSubscription,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return nil, err
|
||||
}
|
||||
subscription.Tags = []string(tags)
|
||||
data := make(map[string]any)
|
||||
err = json.Unmarshal(dataSubscription, &data)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
log.Error().Err(err).Msg("")
|
||||
return nil, err
|
||||
}
|
||||
subscription.Data = data
|
||||
|
||||
Reference in New Issue
Block a user