course

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package course is the course use cases and their model.

It owns which backend to try and in what order. There is no central dispatcher: a feature knows its own alternatives and its own tolerance for incomplete answers, and a shared one would have to learn all of that for every feature.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Name() site.BackendKind
	Requirement() site.Requirement
	List(ctx context.Context, q ListQuery) (ListResult, error)
}

Backend is one way of listing courses. A feature declares the interface it needs; adapters in other packages satisfy it.

type ListQuery

type ListQuery struct {
	// Limit caps the number of courses returned. Zero means the backend's
	// default.
	Limit int
	// Cursor continues a previous listing. It is opaque to callers.
	Cursor string
	// Current keeps only the courses running now. A student's enrolments
	// span every term they have taken, and the question they usually have is
	// about this one.
	Current bool
}

ListQuery limits a listing.

type ListResult

type ListResult struct {
	Courses []Summary
	// Provenance tells the caller which backend answered and whether anything
	// is missing, so an agent can tell "no value" from "could not fetch".
	Provenance site.Provenance
	NextCursor string
}

ListResult is a listing plus how it was obtained.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service lists courses, trying its backends in order.

func NewService

func NewService(backends ...Backend) *Service

NewService builds a Service. The order is the preference order, and the composition root decides it.

func (*Service) List

func (s *Service) List(ctx context.Context, capabilities *site.Capabilities, q ListQuery) (ListResult, error)

List returns the courses this account is enrolled in.

Backends whose requirements are not met are skipped without a request. Once a request has been made, only a "this route cannot do it" error allows the next backend to be tried; anything else is returned as-is so a permission or network problem is never disguised as a missing feature.

type Summary

type Summary struct {
	ID        string
	ShortName string
	FullName  string
	// StartDate and EndDate are nil when the course does not set them. Moodle
	// sends 0 for "unset", which must not become 1970.
	StartDate *time.Time
	EndDate   *time.Time
	Visible   bool
	// Progress is nil when the site does not report it, which is different
	// from a course at 0%.
	Progress *float64
}

Summary is one course as this tool understands it.

It is not Moodle's shape: the adapter maps upstream fields onto this, so a change on their side stops at the adapter instead of reaching the JSON contract.

func (Summary) Running added in v0.2.0

func (s Summary) Running(now time.Time) bool

Running reports whether a course is running at the given moment: started, and not yet ended. A course that sets neither date is taken as running, since nothing says it is over.

Jump to

Keyboard shortcuts

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