50 lines
1004 B
Go
50 lines
1004 B
Go
package mongodb
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type MongoConnection struct {
|
|
Conn *mongo.Client
|
|
}
|
|
|
|
func getConnectionString() string {
|
|
return fmt.Sprintf("mongodb://moxitech:moxitech@mongo:27017")
|
|
}
|
|
|
|
func Connect() (*MongoConnection, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(getConnectionString()))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &MongoConnection{Conn: client}, nil
|
|
}
|
|
|
|
func Authorize(username string, words []string) (string, error) {
|
|
if len(words) > 11 {
|
|
return "", fmt.Errorf("error validation: words list < 12")
|
|
}
|
|
return "STRINGER", nil
|
|
}
|
|
|
|
type User struct {
|
|
Login string `json:"login"`
|
|
Password []byte `json:"password"`
|
|
}
|
|
|
|
type Group struct {
|
|
Users *[]string `json:"users"`
|
|
Blocks *[]Block `json:"blocks"`
|
|
}
|
|
|
|
type Block struct {
|
|
Text *string `json:"text"`
|
|
}
|