Documentation ¶
Index ¶
- Constants
- Variables
- func Close() error
- func Connect(path string) error
- func CreateUser(userName, password string) error
- func GetImages(gender int) (*[]Image, error)
- func GetNames(gender int) (*[]Name, error)
- type Bot
- func (b *Bot) Create() error
- func (b *Bot) Delete() error
- func (b *Bot) GetFatherName() string
- func (b *Bot) GetFavoriteColor() string
- func (b *Bot) GetMessages() (*[]Message, error)
- func (b *Bot) GetMotherName() string
- func (b *Bot) StoreMessages(user *User, msgs []Message) error
- func (b *Bot) UpdateContext(affection, mood float64, pattern *int) error
- type Gender
- type Image
- type Message
- type MessageSender
- type Name
- type User
- type UserError
Constants ¶
const ( // Male is the constant that defines that a bot is male (value = 0) Male = Gender(0) // Female is the constant that defines that a bot is female (value = 1) Female = Gender(1) )
const ( // BotIsSender says that the message was sent by the bot BotIsSender = 0 // UserIsSender says that the message was sent by the user UserIsSender = 1 )
const MessageMaxLength = 200
MessageMaxLength defines the maximum message length that a user can send to a bot
const Year time.Duration = time.Hour * 24 * 365
Year is the duraction of one year in nano seconds
Variables ¶
var ErrBotDoesNotBelongToUser = UserError("the bot does not belong to you")
ErrBotDoesNotBelongToUser is thrown when the sent message is too long
var ErrConnectionClosed = errors.New("connection is closed or not established jet")
ErrConnectionClosed is thrown if a database request is made, but the connection to the database is closed
var ErrInternalServerError = UserError("internal server error")
ErrInternalServerError is thrown if something went wrong which is not ment to be shown to the user
var ErrMessageToLong = UserError("message is too long")
ErrMessageToLong is thrown when the sent message is too long
var ErrNoUserCredentials = UserError("missing user credentials")
ErrNoUserCredentials is shown if no user credentials are provided
var ErrUserNameTaken = UserError("username allready taken")
ErrUserNameTaken is thrown when user can not be created because the name is allready taken
var ErrUserNotExists = UserError("username not found")
ErrUserNotExists is thrown if the user does not exist
var ErrWrongPassword = UserError("wrong password")
ErrWrongPassword is thrown if the user password combination is invalid
Functions ¶
func Connect ¶
Connect creates a connection to a sqlite3 database The given path is the location of the datbase file If the function runs without errors, the database is ready for requests
func CreateUser ¶
CreateUser adds a new user to the database It creates a new entry in the table "User" The password is hashed with bcrypt
Types ¶
type Bot ¶
type Bot struct { // The bots unique id ID int // The bots name, which the user can see Name string // The path to the bots profile picture Image string Gender Gender // The user the bot belongs to. Only this user can communicate with the bot User int // The bots current affection to the user Affection float64 // The bots current mood Mood float64 // Pattern is the recognized pattern id in the last message Pattern *int Birthdate time.Time // FavoriteColor is the primary key of the bots favorite color FavoriteColor int // FatherName is the primary key of the bots fathers name FatherName int // FatherAge is the bots fathers age in years FatherAge int // MotherName is the primary key of the bots mothers name MotherName int // MotherAge is the bots mothers age in years MotherAge int // CreationDate is the point in time when the bot was created by a user CreationDate time.Time }
Bot represents a bots entry in the database A bot is only accessible for one user The entry holds personal information about the bot but also information about the current mood and affection to the user.
func (*Bot) Create ¶
Create creates a bot entry in the database The following fields in the bot struct need to be filled: Name, Image, Gender, User, Affection and Mood If the insertion was successful the generated bot id is saved in the given bot struct.
func (*Bot) GetFatherName ¶
GetFatherName returns the name of the father as string
func (*Bot) GetFavoriteColor ¶
GetFavoriteColor returns the favorite color as string
func (*Bot) GetMessages ¶
GetMessages returns a list of all messages, that the user and bot sent each other
func (*Bot) GetMotherName ¶
GetMotherName returns the name of the mother as string
func (*Bot) StoreMessages ¶
StoreMessages stores messages in database The messages need to be sent between the given bot and user
type Message ¶
type Message struct { // ID is a unique id ID int // The bot who sent the message or received it Bot int // The sender of the message Sender MessageSender // The point in time that the message was sent Timestamp time.Time // The text that was sent Content string }
Message represents database entry of a message A messsage is a text that was sent between the user and a bot Since a bot can only communicate with one user a message is always associated with the bot
type User ¶
User represents a user entry in the database Every person that uses eve needs to have a user entry in the database, because it is used for authentication.
func CheckCredentials ¶
CheckCredentials verifies if the combination of userName and password is valid. The function checks if a user with the given name exists and compares the password with the one in the database. The complete user data is returned if the credentials are valid.
func GetUserForSession ¶
GetUserForSession checks if the given sesssion key is associated with any user in the database. If the key exists in the database the User, which the session belongs to, is returned. An invalid key resolves in the return of a nil pointer
func (*User) GetBot ¶
GetBot returns bot entry from database if bot belongs to user This funtion can be used to check if a bot belongs to the given user.
func (*User) StoreSessionKey ¶
StoreSessionKey saves the session key in the database in the "User" table This session key authenticates the user in further requests The function returns true if the storing was successfull