mirror of
https://github.com/PretendoNetwork/wiiu-chat-authentication.git
synced 2026-03-21 17:24:41 -05:00
42 lines
971 B
Go
42 lines
971 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
var mongoClient *mongo.Client
|
|
var mongoContext context.Context
|
|
var mongoDatabase *mongo.Database
|
|
var mongoCollection *mongo.Collection
|
|
|
|
func connectMongo() {
|
|
mongoClient, _ = mongo.NewClient(options.Client().ApplyURI(os.Getenv("MONGO_URI")))
|
|
mongoContext, _ = context.WithTimeout(context.Background(), 10*time.Second)
|
|
_ = mongoClient.Connect(mongoContext)
|
|
|
|
mongoDatabase = mongoClient.Database("pretendo")
|
|
mongoCollection = mongoDatabase.Collection("nexaccounts")
|
|
}
|
|
|
|
func getNEXAccountByPID(pid uint32) bson.M {
|
|
var result bson.M
|
|
|
|
err := mongoCollection.FindOne(context.TODO(), bson.D{{Key: "pid", Value: pid}}, options.FindOne()).Decode(&result)
|
|
|
|
if err != nil {
|
|
if err == mongo.ErrNoDocuments {
|
|
return nil
|
|
}
|
|
|
|
panic(err)
|
|
}
|
|
|
|
return result
|
|
}
|