Documentation ¶
Overview ¶
Package registry provides a central way to register and use all available formatting options, saving backends, and question types. All options should be registered prior to the program starting, normally through init() Since the questionnaires are handled as immutable, it does not make much sense to register options later.
Index ¶
- func ComparePasswords(method, password, truth string) (bool, error)
- func PasswordMethodExists(method string) bool
- func RegisterDataSafe(t DataSafe, name string) error
- func RegisterFormatType(t Format, name string) error
- func RegisterPasswordMethod(method PasswordMethod, name string) error
- func RegisterQuestionType(f QuestionFactory, name string) error
- type AlreadyRegisteredError
- type DataSafe
- type Format
- type PasswordMethod
- type Question
- type QuestionFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComparePasswords ¶
ComparePasswords compares a password to a 'truth'. The bool represents whether comparison is successful. Error is returned if there is any error during computation. You can savely use it in parallel.
func PasswordMethodExists ¶
RegisterPasswordMethod returns whether the password method is known. You can savely use it in parallel.
func RegisterDataSafe ¶
RegisterDataSafe registeres a data safe. The name of the data safe is used as an identifier and must be unique. You can savely use it in parallel.
func RegisterFormatType ¶
RegisterFormatType registeres a format type. The name of the format type is used as an identifier and must be unique. You can savely use it in parallel.
func RegisterPasswordMethod ¶
func RegisterPasswordMethod(method PasswordMethod, name string) error
RegisterPasswordMethod registeres a password method. The name of the password method is used as an identifier and must be unique. You can savely use it in parallel.
func RegisterQuestionType ¶
func RegisterQuestionType(f QuestionFactory, name string) error
RegisterQuestionType registeres a question type. The name of the question type is used as an identifier and must be unique. You can savely use it in parallel.
Types ¶
type AlreadyRegisteredError ¶
type AlreadyRegisteredError string
AlreadyRegisteredError represents an error where an option is already registeres
func (AlreadyRegisteredError) Error ¶
func (a AlreadyRegisteredError) Error() string
Error returns the error description
type DataSafe ¶
type DataSafe interface { SaveData(questionnaireID string, questionID, data []string) error // Must preserve the order of data for a questionnaireID, questionID combination GetData(questionnaireID string, questionID []string) ([][]string, error) LoadConfig(data []byte) error FlushAndClose() }
DataSafe represents a backend for save storage of questionnaire results. All results must be stored in the same order they are added, grouped by questionnaireID and questionID. However, there reordering is allowed as long as the order for one questionnaireID / questionID combination is retained. All methods must be save for parallel usage.
func GetDataSafe ¶
GetDataSafe returns a data safe. The bool indicates whether it existed. You can only use it if the bool is true.
type Format ¶
Format represents a formatting option. All methods must be save for parallel usage.
func GetFormatType ¶
GetFormatType returns a format type. The bool indicates whether it existed. You can only use it if the bool is true.
type PasswordMethod ¶
PasswordMethod enables to compare the password against different 'truth'. The truth might be plain text, a password hash or similar. Truth must contain every information needed to compare the password. The function must be callable in parallel at the same time. The bool represents whether comparison is successful. Error is returned if there is any error during computation.
type Question ¶
type Question interface { // GetID returns the ID of the question GetID() string // GetHTML returns the HTML representation of the question. // The fragmen must be HTML safe, input name must start with QuestionID_. HTML ids must follow the same rule. GetHTML() template.HTML // GetStatisticsHeader returns the name of the provided question result headers. GetStatisticsHeader() []string // GetStatistics returns the result from the question. // Each slice entry must contain a list of all data in the same length and order as the header. // data holds all database entries currently available. GetStatistics(data []string) [][]string // GetStatisticsDisplay returns a HTML fragment representing the current results. // data holds all database entries currently available. GetStatisticsDisplay(data []string) template.HTML // ValidateInput validates whether the given data can be considered valid (e.g. all required input is there). // The method must return error != nil if the input is not valid. // The method must return error == nil if the input is valid. ValidateInput(data map[string][]string) error // IgnoreRecord determines whether the whole record (meaning all questions of that response) should be ignored without giving feedback to participants. // This can be used to enforce e.g. age restrictions and similar without letting the participant know it. // For most questions, just returning false might be enough. IgnoreRecord(data map[string][]string) bool // GetDatabaseEntry returns a string representation of the results of the question. // The data map returns the values of the POST request of the client, filtered by questions. GetDatabaseEntry(data map[string][]string) string }
Question represents a single question. The results of a question is collected through a normal HTML form, so all questions must provide their results appropriately. The names and ids must start with the provided id. If more is needed, they must add a '_' after the id, and then arbitrary identifier. It is assumed that all questions can be trusted. All methods must be save for parallel usage.
type QuestionFactory ¶
QuestionFactory represents a function to generate a new Question object from the input. The input can be question specific.
func GetQuestionType ¶
func GetQuestionType(name string) (QuestionFactory, bool)
GetQuestionType returns a question type. The bool indicates whether it existed. You can only use it if the bool is true.