Documentation
¶
Index ¶
- type Answer
- type BackgroundImage
- type Content
- type Copyright
- type Extensions
- type FeedbackRange
- type FileReference
- type H5PGoExtension
- func (e *H5PGoExtension) WithDifficulty(difficulty string) *H5PGoExtension
- func (e *H5PGoExtension) WithLearningObjective(objective string) *H5PGoExtension
- func (e *H5PGoExtension) WithSource(source string) *H5PGoExtension
- func (e *H5PGoExtension) WithTags(tags ...string) *H5PGoExtension
- func (e *H5PGoExtension) WithTopic(topic string) *H5PGoExtension
- type H5PPackage
- type Library
- type LibraryDefinition
- type LibraryDependency
- type MultiChoiceQuestion
- type PackageDefinition
- type Question
- type QuestionSet
- type QuestionSetBuilder
- func (b *QuestionSetBuilder) AddMultipleChoiceQuestion(question string, answers []Answer) *QuestionSetBuilder
- func (b *QuestionSetBuilder) AddOverallFeedback(ranges []FeedbackRange) *QuestionSetBuilder
- func (b *QuestionSetBuilder) Build() (*QuestionSet, error)
- func (b *QuestionSetBuilder) SetBackgroundImage(path, mime string) *QuestionSetBuilder
- func (b *QuestionSetBuilder) SetIntroduction(introduction string) *QuestionSetBuilder
- func (b *QuestionSetBuilder) SetPassPercentage(percentage int) *QuestionSetBuilder
- func (b *QuestionSetBuilder) SetProgressType(progressType string) *QuestionSetBuilder
- func (b *QuestionSetBuilder) SetStartButtonText(text string) *QuestionSetBuilder
- func (b *QuestionSetBuilder) SetTitle(title string) *QuestionSetBuilder
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Answer ¶
type Answer struct {
Text string `json:"text"`
Correct bool `json:"correct"`
Feedback string `json:"feedback,omitempty"`
}
Legacy types - use schemas.MultiChoiceParams instead Kept for backward compatibility, will be deprecated
func CreateAnswer ¶
type BackgroundImage ¶
type Content ¶
type Content struct {
QuestionSet *QuestionSet `json:"questionSet,omitempty"`
Params interface{} `json:",omitempty"`
}
type Extensions ¶
type Extensions struct {
H5PGo *H5PGoExtension `json:"h5pGo,omitempty"`
}
Extensions provides a namespace for vendor-specific extensions to H5P content. Standard H5P parsers will ignore unknown fields, making this safe for interoperability. Each vendor should use their own key within the Extensions map.
func NewExtensions ¶
func NewExtensions() *Extensions
NewExtensions creates a new Extensions struct with an initialized H5PGoExtension
type FeedbackRange ¶
func CreateFeedbackRange ¶
func CreateFeedbackRange(from, to int, text string) FeedbackRange
type FileReference ¶
type FileReference struct {
Path string `json:"path"`
}
type H5PGoExtension ¶
type H5PGoExtension struct {
// Section identifies the section/category this question belongs to
// Example: "1. Overview & Fundamentals", "3. Vector RAG"
Section string `json:"section,omitempty"`
// Topic provides a more specific topic within a section
// Example: "RAG Fundamentals", "Chunking Strategies"
Topic string `json:"topic,omitempty"`
// Tags provide flexible categorization with multiple labels
// Example: ["rag", "retrieval", "inference-time"]
Tags []string `json:"tags,omitempty"`
// Difficulty indicates the question difficulty level
// Suggested values: "easy", "medium", "hard"
Difficulty string `json:"difficulty,omitempty"`
// QuestionNumber provides explicit ordering within a question set
QuestionNumber int `json:"questionNumber,omitempty"`
// LearningObjective describes what the question tests
// Example: "Understand the difference between RAG and fine-tuning"
LearningObjective string `json:"learningObjective,omitempty"`
// Source indicates where the question content originated
// Example: "PRESENTATION.md", "Chapter 3"
Source string `json:"source,omitempty"`
// Custom allows arbitrary additional metadata as key-value pairs
Custom map[string]interface{} `json:"custom,omitempty"`
}
H5PGoExtension contains h5p-go specific metadata for questions. These fields are not part of the official H5P specification but provide useful organization and categorization capabilities.
func NewH5PGoExtension ¶
func NewH5PGoExtension(section string, questionNumber int) *H5PGoExtension
NewH5PGoExtension creates a new H5PGoExtension with the given section and question number
func (*H5PGoExtension) WithDifficulty ¶
func (e *H5PGoExtension) WithDifficulty(difficulty string) *H5PGoExtension
WithDifficulty sets the difficulty and returns the extension for chaining
func (*H5PGoExtension) WithLearningObjective ¶
func (e *H5PGoExtension) WithLearningObjective(objective string) *H5PGoExtension
WithLearningObjective sets the learning objective and returns the extension for chaining
func (*H5PGoExtension) WithSource ¶
func (e *H5PGoExtension) WithSource(source string) *H5PGoExtension
WithSource sets the source and returns the extension for chaining
func (*H5PGoExtension) WithTags ¶
func (e *H5PGoExtension) WithTags(tags ...string) *H5PGoExtension
WithTags sets the tags and returns the extension for chaining
func (*H5PGoExtension) WithTopic ¶
func (e *H5PGoExtension) WithTopic(topic string) *H5PGoExtension
WithTopic sets the topic and returns the extension for chaining
type H5PPackage ¶
type H5PPackage struct {
PackageDefinition *PackageDefinition `json:"-"`
Content *Content `json:"-"`
Libraries []*Library `json:"-"`
}
func LoadH5PPackage ¶
func LoadH5PPackage(filePath string) (*H5PPackage, error)
func NewH5PPackage ¶
func NewH5PPackage() *H5PPackage
func (*H5PPackage) AddLibrary ¶
func (pkg *H5PPackage) AddLibrary(lib *Library)
func (*H5PPackage) CreateZipFile ¶
func (pkg *H5PPackage) CreateZipFile(outputPath string) error
func (*H5PPackage) SetContent ¶
func (pkg *H5PPackage) SetContent(content *Content)
func (*H5PPackage) SetPackageDefinition ¶
func (pkg *H5PPackage) SetPackageDefinition(def *PackageDefinition)
type Library ¶
type Library struct {
Definition *LibraryDefinition `json:"-"`
Semantics interface{} `json:"-"`
MachineName string `json:"-"`
Files map[string][]byte `json:"-"`
}
type LibraryDefinition ¶
type LibraryDefinition struct {
Title string `json:"title"`
MachineName string `json:"machineName"`
MajorVersion int `json:"majorVersion"`
MinorVersion int `json:"minorVersion"`
PatchVersion int `json:"patchVersion"`
Runnable bool `json:"runnable"`
Author string `json:"author,omitempty"`
License string `json:"license,omitempty"`
Description string `json:"description,omitempty"`
PreloadedJs []FileReference `json:"preloadedJs,omitempty"`
PreloadedCss []FileReference `json:"preloadedCss,omitempty"`
DropLibraryCss []FileReference `json:"dropLibraryCss,omitempty"`
Dependencies []LibraryDependency `json:"preloadedDependencies,omitempty"`
}
type LibraryDependency ¶
type MultiChoiceQuestion ¶
type MultiChoiceQuestion struct {
Library string `json:"library"`
Params *schemas.MultiChoiceParams `json:"params"`
Extensions *Extensions `json:"extensions,omitempty"`
}
MultiChoiceQuestion represents a typed H5P MultiChoice question
func NewMultiChoiceQuestion ¶
func NewMultiChoiceQuestion(params *schemas.MultiChoiceParams) *MultiChoiceQuestion
NewMultiChoiceQuestion creates a new typed MultiChoice question
func NewMultiChoiceQuestionWithExtensions ¶
func NewMultiChoiceQuestionWithExtensions(params *schemas.MultiChoiceParams, ext *H5PGoExtension) *MultiChoiceQuestion
NewMultiChoiceQuestionWithExtensions creates a new typed MultiChoice question with h5p-go extensions
func (*MultiChoiceQuestion) ToQuestion ¶
func (mcq *MultiChoiceQuestion) ToQuestion() *Question
ToQuestion converts a MultiChoiceQuestion to a generic Question
func (*MultiChoiceQuestion) WithExtensions ¶
func (mcq *MultiChoiceQuestion) WithExtensions(ext *H5PGoExtension) *MultiChoiceQuestion
WithExtensions adds extensions to an existing MultiChoiceQuestion and returns it for chaining
type PackageDefinition ¶
type PackageDefinition struct {
Title string `json:"title"`
Language string `json:"language"`
MainLibrary string `json:"mainLibrary"`
EmbedTypes []string `json:"embedTypes"`
License string `json:"license,omitempty"`
DefaultLanguage string `json:"defaultLanguage,omitempty"`
Author string `json:"author,omitempty"`
PreloadedDependencies []LibraryDependency `json:"preloadedDependencies"`
EditorDependencies []LibraryDependency `json:"editorDependencies,omitempty"`
}
type Question ¶
type Question struct {
Library string `json:"library"`
Params interface{} `json:"params"`
Extensions *Extensions `json:"extensions,omitempty"`
}
type QuestionSet ¶
type QuestionSet struct {
ProgressType string `json:"progressType,omitempty"`
PassPercentage int `json:"passPercentage,omitempty"`
BackgroundImage *BackgroundImage `json:"backgroundImage,omitempty"`
Questions []Question `json:"questions"`
ShowIntroPage bool `json:"showIntroPage,omitempty"`
StartButtonText string `json:"startButtonText,omitempty"`
Introduction string `json:"introduction,omitempty"`
Title string `json:"title,omitempty"`
ShowResultPage bool `json:"showResultPage,omitempty"`
Message string `json:"message,omitempty"`
SolutionButtonText string `json:"solutionButtonText,omitempty"`
OverallFeedback []FeedbackRange `json:"overallFeedback,omitempty"`
}
func FromJSON ¶
func FromJSON(data []byte) (*QuestionSet, error)
func (*QuestionSet) ToJSON ¶
func (qs *QuestionSet) ToJSON() ([]byte, error)
func (*QuestionSet) Validate ¶
func (qs *QuestionSet) Validate() error
type QuestionSetBuilder ¶
type QuestionSetBuilder struct {
// contains filtered or unexported fields
}
Example ¶
builder := NewQuestionSetBuilder()
answers := []Answer{
CreateAnswer("Paris", true),
CreateAnswer("London", false),
CreateAnswer("Berlin", false),
CreateAnswer("Madrid", false),
}
feedbackRanges := []FeedbackRange{
CreateFeedbackRange(0, 50, "You need more practice!"),
CreateFeedbackRange(51, 80, "Good job!"),
CreateFeedbackRange(81, 100, "Excellent work!"),
}
questionSet, err := builder.
SetTitle("Geography Quiz").
SetProgressType("textual").
SetPassPercentage(60).
SetIntroduction("Welcome to our geography quiz!").
SetStartButtonText("Start Quiz").
AddMultipleChoiceQuestion("What is the capital of France?", answers).
AddOverallFeedback(feedbackRanges).
Build()
if err != nil {
log.Fatal(err)
}
jsonData, err := questionSet.ToJSON()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Generated H5P Question Set:\n%s\n", string(jsonData))
loadedQuestionSet, err := FromJSON(jsonData)
if err != nil {
log.Fatal(err)
}
err = loadedQuestionSet.Validate()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Question set validated successfully!\n")
fmt.Printf("Number of questions: %d\n", len(loadedQuestionSet.Questions))
fmt.Printf("Pass percentage: %d%%\n", loadedQuestionSet.PassPercentage)
func NewQuestionSetBuilder ¶
func NewQuestionSetBuilder() *QuestionSetBuilder
func (*QuestionSetBuilder) AddMultipleChoiceQuestion ¶
func (b *QuestionSetBuilder) AddMultipleChoiceQuestion(question string, answers []Answer) *QuestionSetBuilder
func (*QuestionSetBuilder) AddOverallFeedback ¶
func (b *QuestionSetBuilder) AddOverallFeedback(ranges []FeedbackRange) *QuestionSetBuilder
func (*QuestionSetBuilder) Build ¶
func (b *QuestionSetBuilder) Build() (*QuestionSet, error)
func (*QuestionSetBuilder) SetBackgroundImage ¶
func (b *QuestionSetBuilder) SetBackgroundImage(path, mime string) *QuestionSetBuilder
func (*QuestionSetBuilder) SetIntroduction ¶
func (b *QuestionSetBuilder) SetIntroduction(introduction string) *QuestionSetBuilder
func (*QuestionSetBuilder) SetPassPercentage ¶
func (b *QuestionSetBuilder) SetPassPercentage(percentage int) *QuestionSetBuilder
func (*QuestionSetBuilder) SetProgressType ¶
func (b *QuestionSetBuilder) SetProgressType(progressType string) *QuestionSetBuilder
func (*QuestionSetBuilder) SetStartButtonText ¶
func (b *QuestionSetBuilder) SetStartButtonText(text string) *QuestionSetBuilder
func (*QuestionSetBuilder) SetTitle ¶
func (b *QuestionSetBuilder) SetTitle(title string) *QuestionSetBuilder