Documentation
¶
Index ¶
- Constants
- Variables
- func ChoiceUnmarshallValidator(c *Choice) error
- func EmailUnmarshallValidator(e *Email) error
- func IsChoiceType(qt QuestionType) bool
- func IsTextType(qt QuestionType) bool
- func TelephoneUnmarshallValidator(t *Telephone) error
- func TextAreaUnmarshallValidator(t *TextArea) error
- type Choice
- type Email
- type NameIdPath
- type Option
- type Question
- type QuestionPath
- type QuestionType
- type Telephone
- type TextArea
Constants ¶
const ( // QTypeSingleSelect represents a single select field type QTypeSingleSelect QuestionType = "single_select" // QTypeMultipleSelect represents a multiple select field type QTypeMultipleSelect = "multi_select" // QTypeRadio represents a radio field type QTypeRadio = "radio" // QTypeCheckbox represents a checkbox field type QTypeCheckbox = "checkbox" // QTypeTextArea represents a text area field type QTypeTextArea = "text_area" // QTypeInputText represents a text input field type QTypeInputText = "input_text" // QTypeEmail represents an email input field type QTypeEmail = "email" // QTypeTelephone represents a telephone input field type QTypeTelephone = "telephone" )
Any new type, depending on the type of question, should be added to the following: - QTypeChoiceTypes if type is a choice type - QTypeTextTypes if type is a text type if the new type cant be added to either of the above, then: - create a new slice of QuestionType and add the new type to it - append the new slice to AllQuestionTypes - add a new function to check if the new type is of the new slice (e.g. IsChoiceType or IsTextType) - update this comment to include the new type :)
Variables ¶
var AllQuestionTypes = append(QTypeChoiceTypes, QTypeTextTypes...)
AllQuestionTypes is a slice of all question types. Used for validation.
var QTypeChoiceTypes = []QuestionType{ QTypeSingleSelect, QTypeMultipleSelect, QTypeRadio, QTypeCheckbox, }
var QTypeTextTypes = []QuestionType{ QTypeTextArea, QTypeInputText, QTypeEmail, QTypeTelephone, }
Functions ¶
func ChoiceUnmarshallValidator ¶
ChoiceUnmarshallValidator checks if a Choice is valid.
func EmailUnmarshallValidator ¶
EmailUnmarshallValidator validates the unmarshalled email field.
func IsChoiceType ¶ added in v1.1.0
func IsChoiceType(qt QuestionType) bool
IsChoiceType returns true if the question type is a choice type, false otherwise.
func IsTextType ¶ added in v1.1.0
func IsTextType(qt QuestionType) bool
IsTextType returns true if the question type is a text type, false otherwise.
func TelephoneUnmarshallValidator ¶
TelephoneUnmarshallValidator validates the unmarshalled telephone field.
func TextAreaUnmarshallValidator ¶
TextAreaUnmarshallValidator validates the unmarshalled text area field.
Types ¶
type Choice ¶
type Choice struct {
// Options is a list of options for the choice field.
Options []Option `json:"options"`
}
Choice represents a choice field in a survey.
func (*Choice) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type Email ¶
type Email struct {
// AllowedDomains is an optional list of allowed domains for the email field.
AllowedDomains []string `json:"allowedDomains"`
// contains filtered or unexported fields
}
Email represents an email field type.
type NameIdPath ¶
type NameIdPath struct {
// NameId is the identifier of the question.
NameId string
// Path is the location of the question within the survey.
Path []string
// Required indicates whether the question is required.
Required bool
}
NameIdPath represents a path to a question in a survey, including its NameId.
type Option ¶
type Option struct {
// ID is a required identifier for the option.
ID *string `json:"id"`
// Label is a required label for the option.
Label *string `json:"label"`
// Order is an optional order number for the option.
Order *int `json:"order"`
// SubQuestions is an optional list of sub-questions for the option.
SubQuestions []Question `json:"subQuestions"`
}
Option represents a single option in a choice field.
type Question ¶
type Question struct {
// Value is the value of the question, which can be of different types depending on the type of question.
Value any `json:"value"`
// contains filtered or unexported fields
}
Question is a struct that represents a question in a survey.
func (*Question) GetNameIdPaths ¶
func (q *Question) GetNameIdPaths(startPath []string) []*NameIdPath
GetNameIdPaths returns a slice of NameIdPath structs containing the NameId, Required and Path of a Question and its sub-questions. startPath represents the starting path of the Question.
func (*Question) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type QuestionPath ¶ added in v1.1.0
type QuestionPath struct {
Question
// contains filtered or unexported fields
}
QuestionPath represents a Question with its associated path.
type QuestionType ¶
type QuestionType string
QuestionType represents the different types of questions that can exist in a survey.
func ParseToQuestionType ¶
func ParseToQuestionType(v string) (QuestionType, error)
ParseToQuestionType takes a string and returns the corresponding QuestionType, or an error if the string is invalid.
func (*QuestionType) MarshalJSON ¶
func (s *QuestionType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*QuestionType) UnmarshalJSON ¶
func (s *QuestionType) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type Telephone ¶
type Telephone struct {
// AllowedCountryCodes is an optional list of allowed country codes for the telephone field.
AllowedCountryCodes []string `json:"allowedCountryCodes"`
// contains filtered or unexported fields
}
Telephone represents a telephone field type.
type TextArea ¶
type TextArea struct {
// Min is an optional minimum length for the text area field.
Min *int `json:"min"`
// Max is an optional maximum length for the text area field.
Max *int `json:"max"`
// contains filtered or unexported fields
}
TextArea represents a text area field type. It is used to represent the value of a question of type QTypeTextArea and QTypeInputText.