question

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseQuestion

type BaseQuestion struct {
	// NameId is the identifier of the question.
	// Validations:
	// - required
	// - valid name id
	NameId string `json:"nameId" bson:"nameId" validate:"required,validNameId"`

	// Visible is a flag that indicates if the question is visible.
	Visible bool `json:"visible,omitempty" bson:"visible,omitempty"`

	// QTyp is the type of question, such as single_select, multi_select, radio, checkbox, or text_area.
	// Validations:
	// - required
	// - must be a valid question type
	QTyp types.QuestionType `json:"type,omitempty" bson:"type,omitempty" validate:"required,questionType"`

	// Label is a label for the question.
	// Validations:
	// - required
	// - min length: 1
	Label string `json:"label,omitempty" bson:"label,omitempty" validate:"omitempty,min=1"`

	// Required indicates whether the question is required. Defaults to false.
	Required bool `json:"required,omitempty" bson:"required,omitempty"`

	// Metadata is a map of key-value pairs that can be used to store additional information about the question.
	// Validations:
	// - optional
	Metadata map[string]any `json:"metadata,omitempty" bson:"metadata,omitempty" validate:"omitempty"`

	// Position is the position of the question in the survey.
	// The system calculates this field automatically.
	// Validations:
	// - required
	// - min: 1
	Position int `json:"position,omitempty" bson:"position,omitempty" validate:"omitempty,min=1"`

	// Disabled indicates whether the question is disabled. Defaults to false.
	Disabled bool `json:"disabled,omitempty" bson:"disabled,omitempty"`

	// DependsOn is a list of lists of questions and options that the question depends on.
	// The outer lists are evaluated as logical OR, and the inner lists are evaluated as logical AND.
	DependsOn [][]DependsOn `json:"dependsOn,omitempty" bson:"dependsOn,omitempty"`

	// AnswerExpr is an optional expression for custom answer processing,
	// evaluated by the expr-lang/expr engine (https://github.com/expr-lang/expr).
	// When set, the expression result replaces the default type-based extraction in outputs.
	// Environment: ans ([]any) + options (map[nameId]label, only for choice types).
	// When empty, default type-based logic applies.
	AnswerExpr string `json:"answerExpr,omitempty" bson:"answerExpr,omitempty"`
}

BaseQuestion is a struct that contains common fields for all types of questions in a survey.

type DependsOn added in v2.1.1

type DependsOn struct {
	QuestionNameId string `json:"questionNameId" bson:"questionNameId" validate:"required,validNameId"`
	OptionNameId   string `json:"optionNameId" bson:"optionNameId" validate:"required,validNameId"`
}

type Group

type Group struct {
	// NameId is the name id of the group.
	// Validations:
	// - required
	// - valid name id
	NameId string `json:"nameId" bson:"nameId" validate:"required,validNameId"`

	// Title is the title of the group.
	// Validations:
	// - optional
	Title *string `json:"title,omitempty" bson:"title,omitempty" validate:"omitempty"`

	// Description is the description of the group.
	// Validations:
	// - optional
	Description *string `json:"description,omitempty" bson:"description,omitempty" validate:"omitempty"`

	// Hidden is a flag that indicates if the group is hidden (Default: false).
	// Validations:
	// - optional
	Hidden bool `json:"hidden,omitempty" bson:"hidden,omitempty" validate:"omitempty"`

	// Disabled is a flag that indicates if the group is disabled (Default: false).
	// Validations:
	// - optional
	Disabled bool `json:"disabled,omitempty" bson:"disabled,omitempty" validate:"omitempty"`

	// IsExternalSurvey is a flag that indicates if the group is an external survey.
	// When a group is an external survey, it means that:
	// - QuestionsIds length must be 1
	// - The question will be an external survey question id
	// Validations:
	// - validIfExternalSurvey
	IsExternalSurvey bool `json:"isExternalSurvey,omitempty" bson:"isExternalSurvey,omitempty" validate:"validIfExternalSurvey"`

	// AllowRepeat is a flag that indicates if the group can be repeated (Default: false).
	// Validations:
	// - optional
	AllowRepeat bool `json:"allowRepeat,omitempty" bson:"allowRepeat,omitempty" validate:"omitempty"`

	// QuestionsIds is a list of question ids that are associated with this group or the external survey id.
	// Validations:
	//	- optional
	QuestionsIds []string `json:"questionsIds,omitempty" bson:"questionsIds,omitempty"`

	// GroupsOrder is a list of group name ids that defines the order of the groups in the group.
	// Validations:
	//	- optional
	GroupsOrder []string `json:"groupsOrder,omitempty" bson:"groupsOrder,omitempty"`

	// Metadata is a map with additional metadata for the group.
	// Validations:
	// - optional
	Metadata map[string]any `json:"metadata,omitempty" bson:"metadata,omitempty" validate:"omitempty"`

	// Position is the position of the group in the survey.
	// The system calculates this field automatically.
	// Validations:
	// - required
	// - min: 1
	Position int `json:"position,omitempty" bson:"position,omitempty" validate:"omitempty,min=1"`

	// DependsOn is a list of lists of questions and options that the group depends on.
	// The outer lists are evaluated as logical OR, and the inner lists are evaluated as logical AND.
	DependsOn [][]DependsOn `json:"dependsOn,omitempty" bson:"dependsOn,omitempty"`
}

Group is a struct that represents a group of questions.

func (*Group) AddQuestionId

func (g *Group) AddQuestionId(nameId string, position int)

AddQuestionId adds the question with the specified name ID to the group. Args: - nameId: the name ID of the question to add. - position: the position where to add the question. If position is -1, the question will be added at the end of the group.

func (*Group) RemoveQuestionId

func (g *Group) RemoveQuestionId(nameId string) bool

RemoveQuestionId removes the question with the specified name ID from the group. Returns true if the question was removed, false otherwise.

type Question

type Question struct {
	// BaseQuestion contains common fields for all types of questions.
	BaseQuestion `json:",inline" bson:",inline"`

	// Value is the value of the question, which can be of different types depending on the type of question.
	// Validations:
	// - required
	Value any `json:"value,omitempty" bson:"value,omitempty" validate:"required"`
}

Question is a struct that represents a question in a survey.

func (*Question) UnmarshalBSONValue

func (q *Question) UnmarshalBSONValue(_ bsontype.Type, b []byte) error

func (*Question) UnmarshalJSON

func (q *Question) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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