question

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package question provides Question for a Questionnaire.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOption added in v0.0.3

func AddOption[T shared.N](q *Question, o ...option.Option[T])

AddOption adds an option to the question.

func GetOption added in v0.0.3

func GetOption[T shared.N](q Question, id string) (option.Option[T], error)

GetOption returns an option from the question.

Types

type Func

type Func func(o *Meta) error

Func allows to set options.

func WithID added in v0.0.3

func WithID(id string) Func

WithID allows to set the ID of the question.

func WithImageURL

func WithImageURL(imageURL string) Func

WithImageURL sets the question image URL.

func WithMeta

func WithMeta(meta *Meta) Func

WithMeta set the whole meta. Replaces whatever was set before.

func WithOption

func WithOption[T shared.N](opts ...option.Option[T]) Func

WithOption add an option to the question.

func WithRequired

func WithRequired(required bool) Func

WithRequired sets the question as required.

func WithWeight

func WithWeight(weight int) Func

WithWeight sets the question weight.

type Meta

type Meta struct {
	// ID of the question.
	ID string `json:"id" bson:"id"`

	// ImageURL is the URL of the image.
	ImageURL string `json:"url" bson:"url"`

	// Index is the index of the question.
	Index int `json:"index" bson:"index"`

	// Required is a flag to indicate if the question is required.
	Required bool `json:"required" default:"false" bson:"required"`

	// Weight is the weight of the question.
	Weight int `json:"weight" bson:"weight"`
	// contains filtered or unexported fields
}

Meta enriches the question with metadata. Add here anything you need.

type NextQuestionFunc

type NextQuestionFunc func() string

NextQuestionFunc is a function which determines the next question.

type Question

type Question struct {
	common.Common `json:",inline" bson:",inline"`

	// Meta is the metadata of the question.
	Meta Meta `json:"meta" bson:"meta"`

	// Label is the question.
	Label string `json:"label" bson:"label"`

	// Options is a list of options for the question to be answered.
	Options *safeorderedmap.SafeOrderedMap[any] `json:"options" bson:"options"`

	// PreviousQuestionID is the ID of the previous question.
	PreviousQuestionID string `json:"-" bson:"-"`

	// Type of the question.
	Type types.Type `json:"type" bson:"type"`
}

Question with options to be answered.

func MustNew

func MustNew[T shared.N](
	id string,
	label string,
	t types.Type,
	params ...Func,
) Question

MustNew creates a new questionnaire and panics if there's an error.

func New

func New[T shared.N](
	id string,
	label string,
	t types.Type,
	params ...Func,
) (Question, error)

New creates a new Question.

func (*Question) GetID

func (q *Question) GetID() string

GetID returns the ID of the question.

func (*Question) GetIndex added in v0.0.3

func (q *Question) GetIndex() int

GetIndex returns the index of the question.

func (*Question) SetIndex added in v0.0.3

func (q *Question) SetIndex(index int)

SetIndex sets the index of the question.

Jump to

Keyboard shortcuts

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