Documentation
¶
Overview ¶
Package option provides Option for a Question.
Index ¶
- func AnyToOption(v any) any
- type Answer
- type Func
- type NextQuestionFunc
- type Option
- func (o Option[T]) Get() interface{}
- func (o Option[T]) GetID() string
- func (o Option[T]) GetLabel() string
- func (o Option[T]) GetQuestionID() string
- func (o Option[T]) GetState() status.Status
- func (o Option[T]) GetValue() T
- func (o Option[T]) GetWeight() int
- func (o Option[T]) NextQuestionID() string
- func (o Option[T]) SetQuestionID(id string) Option[T]
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyToOption ¶ added in v0.0.3
AnyToOption converts any to the proper Option[Type] then to any.
Types ¶
type Answer ¶
type Answer struct { // ID of the answer. ID string `json:",inline"` // QuestionID is the ID of the question at the time of the answer. QuestionID string `json:"questionId" validate:"required"` // QuestionLabel is the label of the question at the time of the answer. QuestionLabel string `json:"questionLabel" validate:"required"` // QuestionWeight is the weight of the option at the time of the answer. QuestionWeight int `json:"questionWeight"` // OptionID is the ID of the option at the time of the answer. OptionID string `json:"optionId"` // OptionLabel is the label of the option at the time of the answer. OptionLabel string `json:"optionLabel"` // OptionValue is the value at the time of the answer. OptionValue any `json:"optionValue"` // OptionWeight is the weight of the option at the time of the answer. OptionWeight int `json:"optionWeight"` }
Answer is the answer to a question. It's a clone of `answer.Answer` otherwise circular dependency.
type Func ¶
Func allows to set options.
func WithNextQuestionFunc ¶
func WithNextQuestionFunc(f NextQuestionFunc) Func
WithNextQuestionFunc sets the next question function.
func WithNextQuestionID ¶
WithNextQuestionID sets the next question ID.
func WithQuestionID ¶ added in v0.0.8
WithQuestionID sets the weight of the option.
type NextQuestionFunc ¶
type NextQuestionFunc func() string
NextQuestionFunc is a function which determines the next question.
type Option ¶
type Option[T shared.N] struct { common.Common `json:",inline" bson:",inline"` // Label is the label of the option. Label string `json:"label" bson:"label"` // QuestionID is the ID of the question. QuestionID string `json:"questionID" bson:"questionID"` // State sets the State of the option. State status.Status `json:"state" bson:"state"` // Value is the value of the option. Value T `json:"value" bson:"value"` // Weight is the weight of the option. Weight int `json:"weight" bson:"weight"` // contains filtered or unexported fields }
Option is a value for a question.
func MapToOption ¶ added in v0.0.3
MapToOption converts a map[string]any to Option[T].
func (Option[T]) Get ¶ added in v0.0.3
func (o Option[T]) Get() interface{}
Get returns the value of the option.
func (Option[T]) GetQuestionID ¶ added in v0.0.8
GetQuestionID returns the question ID of the option.
func (Option[T]) GetValue ¶
func (o Option[T]) GetValue() T
GetValue returns the value of the option.
func (Option[T]) NextQuestionID ¶
NextQuestionID returns next question index.
func (Option[T]) SetQuestionID ¶ added in v0.0.8
SetQuestionID returns the question ID of the option.
type Options ¶
type Options struct { // ID of the option. ID string `json:"id"` // Group of the option. Group string `json:"group"` // ImageURL is the URL of the image. ImageURL string `json:"url"` // Label is the label of the option. Label string `json:"label"` // NextQuestion is the next question ID. NextQuestionID string `json:"nextQuestionID"` // QuestionID is the ID of the question. QuestionID string `json:"questionID" bson:"questionID"` // state sets the state of the option. State status.Status `json:"state"` // Weight is the weight of the option. Weight int `json:"weight"` }
Options contains the fields shared between request's options.