broker

package
v0.0.0-...-ddf4e43 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoErr         errMsg = iota //no error
	ErrZero                     //simple error
	NoRecord                    //errNoRecord
	InvalidCreds                //errInvalidCredentials
	DuplicateMail               //errDuplicateEmail
)

MoErr and the rest of this block is used for encoding and decoding error types through the gob encoding and decoding (error type does not work)

View Source
const (
	Name           = "name"
	Email          = "email"
	HashedPassword = "hashed_password"
	Created        = "created"
	Role           = "role"
	Active         = "active"
	Online         = "online"
	AgentID        = "agent_id"
	DialogID       = "dialog_id"
	Message        = "message"
	Started        = "started"
	Ended          = "ended"
	Open           = "open"
)

Variables

View Source
var (
	//ErrNoRecord incicates there was not a corresponding record in the DB
	ErrNoRecord = errors.New("models: no matching record found")
	//ErrInvalidCredentials indicates that user supplied an invalid email
	ErrInvalidCredentials = errors.New("models: invalid credentials")
	// ErrDuplicateEmail indicates that email is alreday being used
	ErrDuplicateEmail = errors.New("models: duplicate email")
)

Functions

func ActivationR

func ActivationR(table, role string, people *TableRows) error

ActivationR activates or deactivates agent or admin as requested.

func AddAgentToDialog

func AddAgentToDialog(dialogID, agentID int) error

AddAgentToDialog adds the agent ID to the dialog table

func ChatConnection

func ChatConnection(sendMsg []byte, target string) []byte

ChatConnection sends string data to the far end, waits for the response and returns. for chat and mat, the data is string. For dbmgr, the data is a struct. which is gob encoded before it is sent. Gob encoder is in the broker pkg. TODO: find a way to build a nats connecton pool like the MySQL connection pool to speed up transactions.

func ChgPwdR

func ChgPwdR(table, role, email, password string) error

ChgPwdR sends a request to the dbmgr to change the pawword for the specified email

func EnterMsg

func EnterMsg(table string, dialogID int, message string) error

EnterMsg adds the next messsage into the message table

func InsertEUR

func InsertEUR(table, name, email, password string) error

InsertEUR is for inserting end users (EU) from the front end

func InsertXR

func InsertXR(table, role, name, email, password string) error

InsertXR inserts an administrator into admins table that includes a role X stands for user, agent, or admin

func MakeDialog

func MakeDialog(table string, id, agentID int) error

MakeDialog creates a new entry in the dialog table and returns the dialog_id

func MessageAgent

func MessageAgent(agentID, userID int, message string) (string, error)

MessageAgent sends a message to the agent and gets the reply

func PutLine

func PutLine(table, role string, id int, online bool) error

PutLine moves the agent offline and online

func SelectAgent

func SelectAgent() (agentID int, err error)

SelectAgent executes a transaction on the database and selects an agent and returns the agent ID. No agent available is shown in the error.

Types

type Exchange

type Exchange struct {
	//Table is the name of the table to be processed, for now "admins in all cases."
	Table string
	//Put is list of column names to be put in the database after the SET verb
	//Put is only used by methods and functions that have "put" or "insert"
	//in the Action field
	Put []string
	//SpectList is a mirror image of Spec for building the SQL statement
	SpecList []string
	//Spec is the list of columns that come after the WHERE word
	//Spec will appear both when the Action is put or get but not insert
	Spec [][]interface{} //[]string
	//ScanSpec is specifically the specification for the rows.Scan statement
	ScanSpec [][]interface{}
	//Get is the list of the fields to be returned
	//Get is only used by methods or functions that set Action to "get"
	Get []string
	//See the notes on Person above.
	Tables TableRows
	//Person is the extration of the single People
	//The command for the far end, get,  put, or insert.
	Action string

	ErrType errMsg
	Err     string
}

Exchange is the new API interface to the dbmgr. It is handed to the database get and put methods as is to be processed.

func (*Exchange) DecodeErr

func (e *Exchange) DecodeErr() error

DecodeErr decodes error shipped over gob encoded medium.

func (*Exchange) EncodeErr

func (e *Exchange) EncodeErr(err error)

EncodeErr encodes err for transmission over gob encoded medium. errors don't gob encode.

func (*Exchange) FromGob

func (e *Exchange) FromGob(g []byte) error

FromGob decides Exchange typed shipped over nats

func (*Exchange) ToGob

func (e *Exchange) ToGob() ([]byte, error)

ToGob encodes Exchange type data to be shipped over nats

type TableRow

type TableRow struct {
	ID             int
	DialogID       int
	AgentID        int
	MessageID      int
	Dialog         int //number of dialogs an agent is handling
	Name           string
	Email          string
	Password       string //once the new API is implemented, this field comes out.
	HashedPassword string
	Created        time.Time
	Ended          time.Time
	Role           string
	Active         bool
	Online         bool
	Msg            string
}

TableRow is a direct map of the database columns in exact the same order. data is extracted from the database into each of these fields. All "get" actions populate all fields. For put actions, the fileds that need to be "put" must be populated. The object Person is always used in a slice as []People.

func AuthenticateEUR

func AuthenticateEUR(table, email string) (*TableRow, error)

AuthenticateEUR gob encodes exchData and sends it to the dbmgr over nats EU stands for end user

func AuthenticateXR

func AuthenticateXR(table, role, email string) (*TableRow, error)

AuthenticateXR gob encodes exchData and sends it to the dbmgr over nats X stands for user, agent, or admin

func GetDialog

func GetDialog(table string, id int) (*TableRow, error)

GetDialog returns true if the message is a new dialog and fales if it is not. If the dialog is not new, the UserMsg is populated from the dialog table.

func GetEUR

func GetEUR(table string, id int) (*TableRow, error)

GetEUR gets the user infromation for the database (EU for end user)

func GetXR

func GetXR(table string, id int) (*TableRow, error)

GetXR gob encodes exchData and sends it to the dbmgr over nats X stands for user, agent, or admin

func (*TableRow) BuildInsert

func (p *TableRow) BuildInsert(put []string) []interface{}

BuildInsert uses the "put" slice pattern to build an empty interface slice to be used with the INSERT statement

func (*TableRow) GetBack

func (p *TableRow) GetBack(get []string, g []interface{}) error

GetBack reverses the get item and takes the interface items and gets the underlying data back.

func (*TableRow) GetItems

func (p *TableRow) GetItems(get []string) []interface{}

GetItems uses the get string to generate an interface to be passed to the sql.Execute statement for the INSERT sql command.

func (*TableRow) GetSpec

func (p *TableRow) GetSpec(spec []string) []interface{}

GetSpec builds the specifications to provide to the WHERE clause of SQL

func (*TableRow) Specify

func (p *TableRow) Specify(put, spec []string) []interface{}

Specify builds inspec on the side of the gob decoding. It uses people data and put and spec slices to build the items that need to be ither put into the database or are conditions of the database entry (WHERE condition.)

type TableRows

type TableRows []TableRow

TableRows is a slice so multiple rows can be inserted and extracted

func GetByStatusR

func GetByStatusR(table, role string, status bool) (TableRows, error)

GetByStatusR gets from the specified table a string agents by status (eg. active)

Jump to

Keyboard shortcuts

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