Documentation
¶
Index ¶
- type Database
- func (database *Database) Client() *mongo.Client
- func (database *Database) Connect()
- func (database *Database) Database() *mongo.Database
- func (database *Database) Delete(collection string, query bson.M) error
- func (database *Database) Exists(collection string, query bson.M) (bool, error)
- func (database *Database) Find(collection string, query bson.M, model interface{}, exclude ...string) error
- func (database *Database) Insert(collection string, model interface{}) error
- func (database *Database) Replace(collection string, query bson.M, model interface{}) error
- func (database *Database) SetSCRAMAuthentication(username string, password string)
- type HandlerFunc
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database An abstraction of an active mongodb database connection. The same connection is re-used across all SDK operations to ensure that we don't exceed the connection pool limit
func NewDatabase ¶
NewDatabase - A constructor for the database object. This exists in the event the caller wants to create a new database object without using Viper
func NewDatabaseFromConfig ¶
func NewDatabaseFromConfig() *Database
NewDatabaseFromConfig - A wrapper for NewDatabase. Constructs a new database from configuration values passed in Viper
func (*Database) Connect ¶
func (database *Database) Connect()
Connect to the MongoDB instance defined in the Database object
func (*Database) Database ¶
Database - Getter function for returning a pointer to the MongoDB database
func (*Database) Find ¶
func (database *Database) Find(collection string, query bson.M, model interface{}, exclude ...string) error
Find - Fetch a document from MongoDB and decode the results into the reference passed in the model parameter
func (*Database) Insert ¶
Insert - Insert a single document into the MongoDB collection attached to this Database instance
func (*Database) Replace ¶
Replace - Replace a single document in the MongoDB collection attached to this Database instance
func (*Database) SetSCRAMAuthentication ¶
SetSCRAMAuthentication - Set the credentials for the database connection if they are needed
type HandlerFunc ¶
HandlerFunc - A wrapper for your gin middleware
type Service ¶
type Service struct {
// Name - The name of the Service
Name string
// Port - The port to expose the API on. Defaults to 8080
Port int
// contains filtered or unexported fields
}
Service - An abstraction of a Micro-Service. Responsible for exposing the underlying gin REST API and providing a connection to MongoDB
func FromConfig ¶
func FromConfig() *Service
FromConfig - A wrapper around New. Constructs a new Service struct using values provided by Viper
func (*Service) RegisterEndpoint ¶
func (service *Service) RegisterEndpoint(method string, endpoint string, handler HandlerFunc)
RegisterEndpoint - Wraps the gin function gin.Engine.Handle and registers a new endpoint with the router. The 'handler' parameter should be the logic of your endpoint using the HandlerFunc type