init project
This commit is contained in:
29
pkg/database/mongo/mongo.go
Normal file
29
pkg/database/mongo/mongo.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/local"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) GetDataLog() ([]*local.StartUpLog, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
dataLog, err := s.DB.Collection("startup_log").Find(ctx, bson.M{})
|
||||
if err != nil {
|
||||
log.Println("MASUK SINI")
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Println("Data", dataLog.Current)
|
||||
var logs []*local.StartUpLog
|
||||
errDecode := dataLog.All(ctx, &logs)
|
||||
if errDecode != nil {
|
||||
log.Println(errDecode)
|
||||
return nil, errDecode
|
||||
}
|
||||
log.Println("LOGS :", logs)
|
||||
return logs, nil
|
||||
}
|
||||
Reference in New Issue
Block a user