Documentation ¶
Index ¶
- Constants
- Variables
- func ActivationR(table, role string, people *TableRows) error
- func AddAgentToDialog(dialogID, agentID int) error
- func ChatConnection(sendMsg []byte, target string) []byte
- func ChgPwdR(table, role, email, password string) error
- func EnterMsg(table string, dialogID int, message string) error
- func InsertEUR(table, name, email, password string) error
- func InsertXR(table, role, name, email, password string) error
- func MakeDialog(table string, id, agentID int) error
- func MessageAgent(agentID, userID int, message string) (string, error)
- func PutLine(table, role string, id int, online bool) error
- func SelectAgent() (agentID int, err error)
- type Exchange
- type TableRow
- type TableRows
Constants ¶
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)
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 ¶
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 ¶
ActivationR activates or deactivates agent or admin as requested.
func AddAgentToDialog ¶
AddAgentToDialog adds the agent ID to the dialog table
func ChatConnection ¶
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 InsertXR ¶
InsertXR inserts an administrator into admins table that includes a role X stands for user, agent, or admin
func MakeDialog ¶
MakeDialog creates a new entry in the dialog table and returns the dialog_id
func MessageAgent ¶
MessageAgent sends a message to the agent and gets the reply
func SelectAgent ¶
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) EncodeErr ¶
EncodeErr encodes err for transmission over gob encoded medium. errors don't gob encode.
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 ¶
AuthenticateEUR gob encodes exchData and sends it to the dbmgr over nats EU stands for end user
func AuthenticateXR ¶
AuthenticateXR gob encodes exchData and sends it to the dbmgr over nats X stands for user, agent, or admin
func GetDialog ¶
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 GetXR ¶
GetXR gob encodes exchData and sends it to the dbmgr over nats X stands for user, agent, or admin
func (*TableRow) BuildInsert ¶
BuildInsert uses the "put" slice pattern to build an empty interface slice to be used with the INSERT statement
func (*TableRow) GetBack ¶
GetBack reverses the get item and takes the interface items and gets the underlying data back.
func (*TableRow) GetItems ¶
GetItems uses the get string to generate an interface to be passed to the sql.Execute statement for the INSERT sql command.