surveygo

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

surveygo

Generate and process JSON surveys

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answers

type Answers map[string][]any

Answers is a map of question nameId to its answer value(s).

type Survey

type Survey struct {
	// Title is the title of the survey.
	Title *string `json:"title"`

	// Version is the version of the survey.
	Version *string `json:"version"`

	// Description is the description of the survey.
	Description *string `json:"description"`

	// NameIdPaths is a map of question nameId to its path in the survey json.
	NameIdPaths map[string]string `json:"idPaths"`

	// RequiredNameIds is a list of required question nameIds.
	RequiredNameIds []string `json:"required"`

	// FullJsonSurvey is the full json representation of the survey.
	FullJsonSurvey *string `json:"fullJsonSurvey"`
}

Survey is a struct representation of a survey.

func NewSurvey

func NewSurvey(title, version, description *string) (*Survey, error)

NewSurvey creates a new Survey instance with the given title, version, and description. Title and version are required and an error is returned if they are not provided.

func Parse

func Parse(j string) (*Survey, error)

Parse converts the given json string into a Survey instance.

func ParseBytes

func ParseBytes(b []byte) (*Survey, error)

ParseBytes converts the given json byte slice into a Survey instance.

func (*Survey) AddQuestionBytes

func (s *Survey) AddQuestionBytes(question []byte) error

AddQuestionBytes adds a question to the survey given its representation as a byte array

func (*Survey) AddQuestionJson

func (s *Survey) AddQuestionJson(question string) error

AddQuestionJson adds a question to the survey given its representation as a JSON string

func (*Survey) AddQuestionMap

func (s *Survey) AddQuestionMap(question map[string]any) error

AddQuestionMap adds a question to the survey given its representation as a map[string]any

func (*Survey) Check

func (s *Survey) Check(aws Answers) error

Check verifies if the answers provided are valid for this survey.

func (*Survey) RemoveQuestion

func (s *Survey) RemoveQuestion(nameId string) error

RemoveQuestion removes the question with the specified name ID from the survey

func (*Survey) ToMap

func (s *Survey) ToMap() (map[string]any, error)

ToMap returns the survey as a map representation.

func (*Survey) UpdateQuestionBytes

func (s *Survey) UpdateQuestionBytes(question []byte) error

UpdateQuestionBytes updates a question in the survey given its representation as a byte array

func (*Survey) UpdateQuestionJson

func (s *Survey) UpdateQuestionJson(question string) error

UpdateQuestionJson updates an existing question in the survey with the data provided as a JSON string.

func (*Survey) UpdateQuestionMap

func (s *Survey) UpdateQuestionMap(question map[string]any) error

UpdateQuestionMap updates an existing question in the survey with the data provided as a map.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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