Documentation ¶
Index ¶
- func Disconnect()
- type Credentials
- type Database
- type MongoDb
- func (db *MongoDb) Create(p Product) error
- func (db *MongoDb) Delete(p Product) error
- func (m *MongoDb) DeleteWhosaler(w Wholesalers) error
- func (m *MongoDb) FindWholesalers() []Wholesalers
- func (db *MongoDb) GetAllProducts() []Product
- func (m *MongoDb) GetWhosalerById(w Wholesalers) Wholesalers
- func (m *MongoDb) GetWhosalerName(w Wholesalers) Wholesalers
- func (db *MongoDb) InsertWholesaer(w Wholesalers) error
- func (db *MongoDb) Ping() error
- func (db *MongoDb) ReadById(p Product) Product
- func (db *MongoDb) ReadByMongoId(p Product) Product
- func (db *MongoDb) ReadByWholesalers(name string) []Product
- func (db *MongoDb) SearchByName(p Product) []Product
- func (db *MongoDb) SearchSimilars(p Product) []Product
- func (db *MongoDb) UpdateWholesaler(w Wholesalers) error
- type Product
- type Value
- type Wholesalers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Credentials ¶
type Database ¶
type Database interface { Create(p Product) error ReadById(p Product) Product ReadByWholesalers(name string) []Product Delete(p Product) error }
Interface useful for mocking test, or if need change database
type MongoDb ¶
My database struct
var (
Db *MongoDb
)
vars needed for only created one instance for my access to the database
func Connect ¶
Connect give you a connection to the database, only one instance will be create, to connect with mongo database, we need the URI where are the DB, the user name and password, and will return the instance with an active connection or an error
func (*MongoDb) Create ¶
Inserting product in the database, only when is a new product or when price change, is can't do this, return error
func (*MongoDb) Delete ¶
Delete a product from DB, if can't do this, return an error. And will print when not found matchs
func (*MongoDb) DeleteWhosaler ¶
func (m *MongoDb) DeleteWhosaler(w Wholesalers) error
Delete a product from DB, if can't do this, return an error. And will print when not found matchs
func (*MongoDb) FindWholesalers ¶
func (m *MongoDb) FindWholesalers() []Wholesalers
Reading from database and returning all wholesalers
func (*MongoDb) GetAllProducts ¶
GetAllProducts return all products from database
func (*MongoDb) GetWhosalerById ¶
func (m *MongoDb) GetWhosalerById(w Wholesalers) Wholesalers
Reading from database, a product identified with his ID
func (*MongoDb) GetWhosalerName ¶
func (m *MongoDb) GetWhosalerName(w Wholesalers) Wholesalers
Reading from database, a product identified with his ID
func (*MongoDb) InsertWholesaer ¶
func (db *MongoDb) InsertWholesaer(w Wholesalers) error
func (*MongoDb) Ping ¶
Ping sends a ping command to verify that the client can connect to the deployment.
func (*MongoDb) ReadByMongoId ¶
Reading from database, a product identified with his ID
func (*MongoDb) ReadByWholesalers ¶
Reading from database and returning all products from one wholesaler
func (*MongoDb) SearchByName ¶
func (*MongoDb) SearchSimilars ¶
func (*MongoDb) UpdateWholesaler ¶
func (db *MongoDb) UpdateWholesaler(w Wholesalers) error
type Product ¶
type Product struct { Id_ primitive.ObjectID `bson:"_id,omitempty"` Id string `bson:"id,omitempty"` Name string `bson:"name,omitempty"` Image string Description string Price []Value `bson:"prices,omitempty"` Stock string Wholesaler string }
Data product needed, not mather what wholesaler get data
type Wholesalers ¶
type Wholesalers struct { Id primitive.ObjectID `bson:"_id,omitempty"` Login string `json:"login" bson:"login"` User string `json:"user" bson:"user"` Pass string `json:"pass" bson:"pass"` Searchpage string `json:"searchpage" bson:"searchpage"` Name string `json:"name" bson:"name"` EndPhrase string `json:"endphrase"` EndPhraseDiv string `json:"endphrasediv"` }