registry

package
v0.0.0-...-c20b901 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePasswords

func ComparePasswords(method, password, truth string) (bool, error)

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

func PasswordMethodExists(method string) bool

RegisterPasswordMethod returns whether the password method is known. You can savely use it in parallel.

func RegisterDataSafe

func RegisterDataSafe(t DataSafe, name string) error

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

func RegisterFormatType(t Format, name string) error

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

func GetDataSafe(name string) (DataSafe, bool)

GetDataSafe returns a data safe. The bool indicates whether it existed. You can only use it if the bool is true.

type Format

type Format interface {
	Format(b []byte) template.HTML
	FormatClean(b []byte) template.HTML
}

Format represents a formatting option. All methods must be save for parallel usage.

func GetFormatType

func GetFormatType(name string) (Format, bool)

GetFormatType returns a format type. The bool indicates whether it existed. You can only use it if the bool is true.

type PasswordMethod

type PasswordMethod func(password, truth string) (bool, error)

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

type QuestionFactory func(data []byte, id string, language string) (Question, error)

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.

Jump to

Keyboard shortcuts

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