structs

package
v0.0.0-...-51710b4 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package structs supplies project-wide needed data structures, types and constants for the server and the command-line tool.

Package structs supplies project-wide needed data structures, types and constants for the server and the command-line tool.

Index

Constants

View Source
const RandomIDLength int = 10

RandomIDLength is the length of the ticket and mail ids.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIConfig

type CLIConfig struct {
	Host string
	Port uint16
	Cert string
}

CLIConfig is a struct to hold the CLI config parameters provided on startup.

type CliErrMessage

type CliErrMessage string

CliErrMessage defines different error messages printed when the command-line tool faces an error.

const (
	TooManyInputs CliErrMessage = "too many successive wrong user inputs. Aborting program execution.\n"
	NoValidOption CliErrMessage = "not within the range of valid options"
	EmptyString   CliErrMessage = "string is empty"
	InvalidEmail  CliErrMessage = "not a valid email address"
)

Various error messages for wrong user inputs

type CliMessage

type CliMessage string

CliMessage defines different standard messages used by the command-line interface that are printed to the console.

const (
	// RequestCommandInput is the message for requesting
	// a command input.
	RequestCommandInput CliMessage = "\nTo fetch Mails from the server, type '0'\n" +
		"To send an email to the server type '1'\n" +
		"To exit this program type '2'\n" +
		"Command: "

	// CommandNotAccepted is the error message if a command
	// is not recognized.
	CommandNotAccepted CliMessage = "Input not accepted, error: "

	// RequestEmailAddress it the message to prompt the user
	// for a valid e-mail input.
	RequestEmailAddress CliMessage = "Please enter your email address. It has to be valid.\nEmail address: "

	// RequestSubject is the message to prompt the user for
	// a ticket subject.
	RequestSubject CliMessage = "Please enter the subject line.\nSubject: "

	// RequestMessage is the message to prompt the user for
	// a ticket message.
	RequestMessage CliMessage = "Please enter the body of the message.\nMessage: "

	// RequestTicketID is the message to prompt the user for
	// an optional ticket id.
	RequestTicketID CliMessage = "If applicable please enter the ticket ID. If left empty, " +
		"a new ticket will be created.\nTicket ID (optional): "

	// To is the string for the output of the recipient of
	// an e-mail.
	To CliMessage = "To: "

	// Subject is the string for the output of the subject
	// of a ticket.
	Subject CliMessage = "Subject: "
)

Messages of the command-line tool

type Command

type Command int

Command represents a command-line interface command. This can be either Fetch, Submit or Exit.

const (
	// CommandFetch is the CLI command to fetch emails
	// from the server.
	CommandFetch Command = iota

	// CommandSubmit is the CLI command to submit an
	// email to the server.
	CommandSubmit

	// CommandExit is the CLI command to exit the CLI.
	CommandExit
)

func (Command) String

func (c Command) String() string

String converts a command to its string representation.

type Data

type Data struct {
	Session Session
	Tickets map[string]Ticket
	Users   map[string]User
}

Data holds session and ticket data to parse to the web templates.

type DataSingleTicket

type DataSingleTicket struct {
	Session Session
	Ticket  Ticket
	Tickets map[string]Ticket
	Users   map[string]User
}

DataSingleTicket holds the session and ticket data for a call to a single ticket.

type Entry

type Entry struct {
	Date          time.Time `json:"id"`
	FormattedDate string    `json:"formattedDate"`
	User          string    `json:"user"`
	Text          string    `json:"text"`
	ReplyType     string    `json:"replyType"`
}

Entry describes a single reply within a ticket.

type JSONMap

type JSONMap map[string]interface{}

JSONMap is a type for mapping JSON keys to JSON values. It is mostly used inside the Mail API.

type LogConfig

type LogConfig struct {
	LogLevel  LogLevel
	Verbose   bool
	FullPaths bool
}

LogConfig defines the logging configuration for the server provided by the startup configuration flags.

type LogLevel

type LogLevel int

LogLevel is a type that defines the level of logging. A high log level such as INFO means that more information and actions are logged to the console. A low log level suppresses the output of messages of a higher log level.

const (
	// LevelInfo is the default log level (all messages
	// are logged).
	LevelInfo LogLevel = iota

	// LevelWarning logs warnings, errors and fatal errors.
	LevelWarning

	// LevelError only logs errors and fatal errors.
	LevelError

	// LevelFatal only logs fatal errors (not recommended).
	// Fatal errors are always logged.
	LevelFatal

	// LevelTestDebug is an additional log level used only
	// for debugging inside tests (not configurable).
	LevelTestDebug
)

func AsLogLevel

func AsLogLevel(logLevelString string) LogLevel

AsLogLevel converts a given log level string to a log level. If the log level string is not defined, the return value is -1.

func (LogLevel) String

func (level LogLevel) String() string

String converts a log level to its corresponding output string used in the log.

type Mail

type Mail struct {
	ID      string `json:"id"`
	From    string `json:"from"`
	To      string `json:"to"`
	Subject string `json:"subject"`
	Message string `json:"message"`
}

Mail struct holds the information for a received email in order to create new tickets or answers.

type ServerConfig

type ServerConfig struct {
	// Port is the port the server is listening to.
	Port uint16

	// Tickets is the directory in which
	// all tickets are stored.
	Tickets string

	// User is the path to the users.json file.
	Users string

	// Mails is the directory in which all
	// mails are stored.
	Mails string

	// Cert is the path to the SSL
	// Certificate file.
	Cert string

	// Key is the path to the SSL Key file.
	Key string

	// Web is the root directory of the server
	// where web resources are located.
	Web string
}

ServerConfig is a struct to hold the config parameters provided on startup.

type Session

type Session struct {
	ID           string
	User         User
	CreationTime time.Time
	IsLoggedIn   bool
}

Session is a struct that holds session variables for a certain user.

type SessionManager

type SessionManager struct {
	Name    string
	Session Session
	TTL     int64
}

SessionManager holds a session and operates on a it.

type Status

type Status int

Status is an enum to represent the current status of a ticket.

const (
	// StatusOpen means the ticket is opened and has
	// no assignee.
	StatusOpen Status = iota

	// StatusInProgress means the ticket is being
	// processed by an assignee.
	StatusInProgress

	// StatusClosed means the ticket has been closed.
	StatusClosed
)

func (Status) String

func (status Status) String() string

String converts a ticket status to its corresponding description used in the outgoing mails.

type Ticket

type Ticket struct {
	ID       string  `json:"id"`
	Subject  string  `json:"subject"`
	Status   Status  `json:"status"`
	User     User    `json:"user"`
	Customer string  `json:"customer"`
	Entries  []Entry `json:"entries"`
	MergeTo  string  `json:"mergeTo"`
}

Ticket represents a ticket.

type User

type User struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Username    string `json:"username"`
	Mail        string `json:"mail"`
	Hash        string `json:"hash"`
	IsOnHoliday bool   `json:"isOnHoliday"`
}

User is the model for a user that works on tickets.

Directories

Path Synopsis
Package defaults defines default constraints for the server and the test suite.
Package defaults defines default constraints for the server and the test suite.

Jump to

Keyboard shortcuts

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