controllers

package
v0.0.0-...-30dc2fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPerson

func AddPerson(p Person) (*mongo.InsertOneResult, error)

AddPerson adds a record of Person in people collection

func CollectionRef

func CollectionRef(db, col string) *mongo.Collection

CollectionRef returns a pointer to the respective collection in database

func ConnectDatabase

func ConnectDatabase() (*mongo.Client, context.CancelFunc)

ConnectDatabase connects to the mongo database and returns a Client

func FormatErrorMesssage

func FormatErrorMesssage(err error) []byte

FormatErrorMesssage formats a server error message

Types

type Person

type Person struct {
	ID        primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
	FirstName string             `json:"firstname,omitempty" bson:"firstname,omitempty"`
	LastName  string             `json:"lastname,omitempty" bson:"lastname,omitempty"`
}

Person type for to represent a person

func FindAll

func FindAll() ([]Person, error)

FindAll returns all the records in people

func FindPersonByID

func FindPersonByID(id primitive.ObjectID) (Person, error)

FindPersonByID finds the person using id and returns it

func FindPersonByIDAndDelete

func FindPersonByIDAndDelete(id primitive.ObjectID) (Person, error)

FindPersonByIDAndDelete finds and deletes the person document

type ServerError

type ServerError struct {
	Message string `json:"message"`
}

ServerError helps handle error responses

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL