api

package
v0.0.0-...-94e6d93 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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"
)
View Source
var ReleaseBuild = releaseBuild == "true"

ReleaseBuild indicates whether this build is a release build (true) or a debug build (false)

Functions

func CancelTask

func CancelTask(ctx context.Context, ref uint32)

func CrashReporter

func CrashReporter(ctx context.Context)

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

func FormatBytes(bytes float64) string

FormatBytes returns the passed bytes as a human readable string

func Log

func Log(ctx context.Context, level LogLevel, message string, args ...interface{})

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

func ResourcePath(ctx context.Context) string

ResourcePath returns the path to the bundled resource files

func RunTask

func RunTask(ctx context.Context, ref uint32, task func(context.Context) error)

RunTask updates the context with the necessary task info and handles errors as well as panics from the task.

func SetProgress

func SetProgress(ctx context.Context, progress float32, description string)

SetProgress updates the progress of the passed task (ref is the task ID)

func SettingsPath

func SettingsPath(ctx context.Context) string

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 Stacktrace(skip int) string

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

func UpdateTask(ctx context.Context, msg interface{}) error

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 LogLevel

type LogLevel int

LogLevel indicates the severity of a log message

const (
	LogDebug LogLevel = iota + 1
	LogInfo
	LogWarn
	LogError
	LogFatal
)

These are the available log levels

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.

type TaskStep

type TaskStep struct {
	Description string
	From        float32
	To          float32
}

TaskStep contains common step parameters to make function calls related to task steps simpler

Jump to

Keyboard shortcuts

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