logger auth error
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"logger/data"
|
||||
"net/http"
|
||||
)
|
||||
@ -18,6 +19,7 @@ func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) {
|
||||
app.errorJSON(w, err)
|
||||
return
|
||||
}
|
||||
log.Println("requestpayload", requestPayload)
|
||||
|
||||
// insert data
|
||||
event := data.LogEntry{
|
||||
@ -25,6 +27,8 @@ func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) {
|
||||
Data: requestPayload.Data,
|
||||
}
|
||||
|
||||
log.Println("event", event)
|
||||
|
||||
err = app.Models.LogEntry.Insert(event)
|
||||
if err != nil {
|
||||
app.errorJSON(w, err)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
@ -42,6 +43,8 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
client = mongoClient
|
||||
|
||||
app := Config{
|
||||
Models: data.New(client),
|
||||
}
|
||||
@ -75,6 +78,12 @@ func connectToMongo() (*mongo.Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result bson.M
|
||||
if err = client.Database("Test").RunCommand(context.TODO(), bson.D{{Key: "ping", Value: 1}}).Decode(&result); err != nil {
|
||||
log.Println("Error ping:", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Println("Connected to Mongo")
|
||||
|
||||
return client, nil
|
||||
|
Reference in New Issue
Block a user