Documentation ¶
Index ¶
- Variables
- func CancelTask(ctx context.Context, ref uint32)
- func CrashReporter(ctx context.Context)
- func DispatchMessage(ctx context.Context, event *client.ClientSentEvent) error
- func FormatBytes(bytes float64) string
- func Log(ctx context.Context, level LogLevel, message string, args ...interface{})
- func ProgressCopier(ctx context.Context, stepInfo TaskStep, length int64, input io.Reader, ...) (int, error)
- func ResourcePath(ctx context.Context) string
- func RunTask(ctx context.Context, ref uint32, task func(context.Context) error)
- func SetProgress(ctx context.Context, progress float32, description string)
- func SettingsPath(ctx context.Context) string
- func Stacktrace(skip int) string
- func TaskLog(ctx context.Context, level client.LogMessage_LogLevel, msg string, ...)
- func UpdateTask(ctx context.Context, msg interface{}) error
- func WithKnossosContext(ctx context.Context, params KnossosCtxParams) context.Context
- func WithTaskContext(ctx context.Context, params TaskCtxParams) context.Context
- type KnossosCtxParams
- type LogLevel
- type SpeedTracker
- type TaskCtxParams
- type TaskStep
Constants ¶
This section is empty.
Variables ¶
var ( // Version contains the compiles libknossos version Version = "0.0.1" // Commit contains a short hash pointing to the commit that was used to compile libknossos Commit = "ffffff" // TwirpEndpoint points to Nebula's Twirp endpoint. This can be used to quickly switch between production // and dev environments. TwirpEndpoint = "https://nu.fsnebula.org/" // SyncEndpoint points to Nebula's modsync endpoint SyncEndpoint = "https://nu.fsnebula.org/sync" )
var ReleaseBuild = releaseBuild == "true"
ReleaseBuild indicates whether this build is a release build (true) or a debug build (false)
Functions ¶
func CancelTask ¶
func CrashReporter ¶
func DispatchMessage ¶
func DispatchMessage(ctx context.Context, event *client.ClientSentEvent) error
DispatchMessage delivers a progress message to the hosting application. This can be used to update the UI, generate log messages, etc. Knossos itself uses this for progress displays. The passed context must have been prepared with WithKnossosContext().
func FormatBytes ¶
FormatBytes returns the passed bytes as a human readable string
func Log ¶
Log records the passed log message in the hosting application's log. The passed context must have been prepared with WithKnossosContext().
func ProgressCopier ¶
func ProgressCopier(ctx context.Context, stepInfo TaskStep, length int64, input io.Reader, output io.Writer) (int, error)
ProgressCopier copies all available data from input to output while reporting the current progress and speed to the given task (ref is the task ID). It returns the speed in bytes / s on success or an error.
func ResourcePath ¶
ResourcePath returns the path to the bundled resource files
func RunTask ¶
RunTask updates the context with the necessary task info and handles errors as well as panics from the task.
func SetProgress ¶
SetProgress updates the progress of the passed task (ref is the task ID)
func SettingsPath ¶
SettingsPath returns the path to the current settings directory (either the current portable directory or the default settings folder inside the user's profile)
func Stacktrace ¶
func TaskLog ¶
func TaskLog(ctx context.Context, level client.LogMessage_LogLevel, msg string, args ...interface{})
TaskLog appends the passed log message to the given task (ref is the task ID)
func UpdateTask ¶
UpdateTask updates the state of a task started by the UI (JavaScript). `ref` contains the task ID and is used by the UI to find the corresponding UI elements. Usually, you won't call this function directly and instead use either SetProgress() or TaskLog().
func WithKnossosContext ¶
func WithKnossosContext(ctx context.Context, params KnossosCtxParams) context.Context
WithKnossosContext stores the passed callbacks in the context which allows it to be used with Log() and DispatchMessage()
func WithTaskContext ¶
func WithTaskContext(ctx context.Context, params TaskCtxParams) context.Context
WithTaskContext stores the passed task info in the context
Types ¶
type KnossosCtxParams ¶
type KnossosCtxParams struct { // LogCallback is a function that records the passed message in the host application's logging system LogCallback func(LogLevel, string, ...interface{}) // MessageCallback receives progress and status messages which provide details for ongoing tasks MessageCallback func(*client.ClientSentEvent) error SettingsPath string ResourcePath string }
KnossosCtxParams acts as a container for important info stored in the context
type SpeedTracker ¶
type SpeedTracker struct {
// contains filtered or unexported fields
}
SpeedTracker calculates the speed of a transfer operation
func NewSpeedTracker ¶
func NewSpeedTracker() *SpeedTracker
NewSpeedTracker creates a new SpeedTracker instance
func (*SpeedTracker) GetSpeed ¶
func (st *SpeedTracker) GetSpeed() float64
GetSpeed calculates the current transfer speed based on the samples taken through Track()
func (*SpeedTracker) Track ¶
func (st *SpeedTracker) Track(bytes int)
Track records that the passed amount of bytes have been transferred
type TaskCtxParams ¶
type TaskCtxParams struct {
Ref uint32
}
TaskCtxParams stores info related to the current task
func GetTaskContext ¶
func GetTaskContext(ctx context.Context, required bool) *TaskCtxParams
GetTaskContext retrieves the current task info from the passed context. If required is true and no info is available, the function panics. Otherwise, nil is returned.