option

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: 4 Imported by: 0

Documentation

Overview

Package option provides Option for a Question.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToOption added in v0.0.3

func AnyToOption(v any) any

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

type Func func(o *Options) error

Func allows to set options.

func WithGroup added in v0.0.2

func WithGroup(group string) Func

WithGroup sets the group of an option.

func WithID added in v0.0.3

func WithID(id string) Func

WithID sets the ID of the option.

func WithLabel

func WithLabel(label string) Func

WithLabel sets the label of the option.

func WithNextQuestionFunc

func WithNextQuestionFunc(f NextQuestionFunc) Func

WithNextQuestionFunc sets the next question function.

func WithNextQuestionID

func WithNextQuestionID(id string) Func

WithNextQuestionID sets the next question ID.

func WithQuestionID added in v0.0.8

func WithQuestionID(id string) Func

WithQuestionID sets the weight of the option.

func WithState

func WithState(s status.Status) Func

WithState sets the state of the option.

func WithWeight

func WithWeight(w int) Func

WithWeight 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

func MapToOption[T shared.N](m map[string]any) (Option[T], error)

MapToOption converts a map[string]any to Option[T].

func MustNew

func MustNew[T shared.N](value T, p ...Func) Option[T]

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

func New

func New[T shared.N](value T, params ...Func) (Option[T], error)

New creates a new Option.

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]) GetID

func (o Option[T]) GetID() string

GetID returns the ID of the option.

func (Option[T]) GetLabel

func (o Option[T]) GetLabel() string

GetLabel returns the label of the option.

func (Option[T]) GetQuestionID added in v0.0.8

func (o Option[T]) GetQuestionID() string

GetQuestionID returns the question ID of the option.

func (Option[T]) GetState

func (o Option[T]) GetState() status.Status

GetState returns the state determiner function.

func (Option[T]) GetValue

func (o Option[T]) GetValue() T

GetValue returns the value of the option.

func (Option[T]) GetWeight

func (o Option[T]) GetWeight() int

GetWeight returns the weight of the option.

func (Option[T]) NextQuestionID

func (o Option[T]) NextQuestionID() string

NextQuestionID returns next question index.

func (Option[T]) SetQuestionID added in v0.0.8

func (o Option[T]) SetQuestionID(id string) Option[T]

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.

Jump to

Keyboard shortcuts

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