Documentation
¶
Index ¶
- Constants
- func CreateSpinner(appConfig *app.Config)
- func IsInteractive(appConfig *app.Config) bool
- func IsTTY() bool
- func MessageWithHint(message string, full bool) string
- func RegisterFieldFormatter(fn func(key string, value interface{}) (string, bool))
- func SetWebSocketHub(hub WebSocketBroadcaster)
- func StopSpinner(appConfig *app.Config)
- func TranslateKey(key string) string
- func UnmarshalField(body map[string]json.RawMessage, key string, target interface{}) error
- func WriteHTTPError(rw http.ResponseWriter, err error)
- type APIError
- type APIResponse
- type EventData
- type NotificationOption
- type Reporter
- type TaskResultEvent
- type WebSocketBroadcaster
Constants ¶
const ( EventTypeNotification = "NOTIFICATION" EventTypeProgress = "PROGRESS" EventTypeTaskResult = "TASK_RESULT" )
const ( StateBefore = "BEFORE" StateAfter = "AFTER" )
const ( EventDistroUpdate = "distrobox.Update" EventDistroContainerAdd = "distrobox.ContainerAdd" EventDistroSavePackagesToDB = "distro.SavePackagesToDB" EventDistroGetContainerList = "distro.GetContainerList" EventDistroExportingApp = "distro.ExportingApp" EventDistroGetContainerInfo = "distro.GetContainerOsInfo" EventDistroCreateContainer = "distro.CreateContainer" EventDistroRemoveContainer = "distro.RemoveContainer" EventDistroInstallPackage = "distro.InstallPackage" EventDistroRemovePackage = "distro.RemovePackage" EventDistroGetPackages = "distro.GetPackages" EventDistroGetPackageOwner = "distro.GetPackageOwner" EventDistroGetPathByPkg = "distro.GetPathByPackageName" EventDistroGetInfoPackage = "distro.GetInfoPackage" EventDistroUpdatePackages = "distro.UpdatePackages" EventDistroGetPackagesQuery = "distro.GetPackagesQuery" EventSystemWorking = "system.Working" EventSystemUpgrade = "system.Upgrade" EventSystemCheck = "system.Check" EventSystemUpdate = "system.Update" EventSystemInstall = "system.Install" EventSystemRemove = "system.Remove" EventSystemCheckInstall = "system.CheckInstall" EventSystemCheckRemove = "system.CheckRemove" EventSystemCheckUpgrade = "system.CheckUpgrade" EventSystemImageUpdate = "system.ImageUpdate" EventSystemImageApply = "system.ImageApply" EventSystemImageSwitch = "system.ImageSwitch" EventSystemUpdateKernel = "system.UpdateKernel" EventSystemUpdateSTPLR = "system.UpdateSTPLR" EventSystemAptUpdate = "system.AptUpdate" EventSystemSavePackagesToDB = "system.SavePackagesToDB" EventSystemSaveImageToDB = "system.SaveImageToDB" EventSystemBuildImage = "system.BuildImage" EventSystemImageModule = "system.imageModule" EventSystemSwitchImage = "system.SwitchImage" EventSystemCheckUpdateBaseImage = "system.CheckAndUpdateBaseImage" EventSystemBootcUpgrade = "system.bootcUpgrade" EventSystemPruneOldImages = "system.pruneOldImages" EventSystemUpdateAllPackagesDB = "system.updateAllPackagesDB" EventSystemUpdateApplications = "system.UpdateApplications" EventSystemDownloadProgress = "system.downloadProgress" EventSystemInstallProgress = "system.installProgress" EventSystemPullImage = "system.pullImage" EventSystemLintTmpfiles = "system.LintTmpfiles" EventSystemLintSysusers = "system.LintSysusers" EventSystemLintRunTmp = "system.LintRunTmp" EventApplicationUpdate = "application.Update" EventApplicationSaveToDB = "application.SaveToDB" EventBootcLayers = "service.bootc-layers" EventBootcDownload = "service.bootc-download" EventKernelCurrent = "kernel.CurrentKernel" EventKernelList = "kernel.ListKernels" EventKernelListModules = "kernel.ListKernelModules" EventKernelInstall = "kernel.InstallKernel" EventKernelCheckInstall = "kernel.CheckInstallKernel" EventKernelUpdate = "kernel.UpdateKernel" EventKernelCheckUpdate = "kernel.CheckUpdateKernel" EventKernelClean = "kernel.CleanOldKernels" EventKernelCheckClean = "kernel.CheckCleanOldKernels" EventKernelInstallMods = "kernel.InstallKernelModules" EventKernelCheckInstallMods = "kernel.CheckInstallKernelModules" EventKernelRemoveMods = "kernel.RemoveKernelModules" EventKernelCheckRemoveMods = "kernel.CheckRemoveKernelModules" EventKernelRemove = "kernel.RemovePackage" EventKernelCheckRemove = "kernel.CheckRemovePackage" )
Имена событий — константы для использования в WithEventName.
Variables ¶
This section is empty.
Functions ¶
func CreateSpinner ¶
CreateSpinner создание и запуск спиннера.
func IsInteractive ¶
IsInteractive возвращает true если формат text и терминал интерактивный (для TUI и других штук)
func MessageWithHint ¶
MessageWithHint дополняет message подсказкой об использовании --full
func RegisterFieldFormatter ¶
RegisterFieldFormatter добавляет форматтер значения поля для текстового вывода
func SetWebSocketHub ¶
func SetWebSocketHub(hub WebSocketBroadcaster)
SetWebSocketHub устанавливает WebSocket hub для отправки событий
func StopSpinner ¶
StopSpinner останавливает активный спиннер.
func TranslateKey ¶
TranslateKey принимает ключ и возвращает английский текст.
func UnmarshalField ¶
func UnmarshalField(body map[string]json.RawMessage, key string, target interface{}) error
UnmarshalField извлекает и десериализует поле из тела запроса
func WriteHTTPError ¶
func WriteHTTPError(rw http.ResponseWriter, err error)
WriteHTTPError записывает классифицированную ошибку в HTTP-ответ. Если ошибка является APMError, используется соответствующий HTTP-статус. Иначе возвращается 500 Internal Server Error.
Types ¶
type APIResponse ¶
type APIResponse struct {
Data interface{} `json:"data"`
Error *APIError `json:"error"`
Transaction string `json:"transaction,omitempty"`
}
func ErrorResponseFromError ¶
func ErrorResponseFromError(err error) APIResponse
func OK ¶
func OK(data interface{}) APIResponse
type EventData ¶
type EventData struct {
Name string `json:"name"`
View string `json:"message"`
State string `json:"state"`
Type string `json:"type"`
ProgressPercent float64 `json:"progress"`
ProgressDone string `json:"progressDone"`
Transaction string `json:"transaction"`
}
EventData содержит данные события.
type NotificationOption ¶
type NotificationOption func(*EventData)
NotificationOption определяет функцию-опцию для настройки EventData.
func WithEventName ¶
func WithEventName(name string) NotificationOption
WithEventName задаёт имя события.
func WithEventView ¶
func WithEventView(name string) NotificationOption
WithEventView задаёт текст отображения события
func WithProgress ¶
func WithProgress(isProgress bool) NotificationOption
WithProgress указывает, что событие является прогрессом.
func WithProgressDoneText ¶
func WithProgressDoneText(text string) NotificationOption
WithProgressDoneText задаёт текст в конце прогресса.
func WithProgressPercent ¶
func WithProgressPercent(percent float64) NotificationOption
WithProgressPercent задаёт процент выполнения.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter инкапсулирует доставку ответов и событий приложения.
func NewReporter ¶
NewReporter создаёт Reporter поверх appConfig.
func (*Reporter) CliResponse ¶
func (r *Reporter) CliResponse(ctx context.Context, resp APIResponse) error
CliResponse рендерит APIResponse в выбранном формате (text/json/dbus/http).
func (*Reporter) CreateEventNotification ¶
func (r *Reporter) CreateEventNotification(ctx context.Context, state string, opts ...NotificationOption)
CreateEventNotification создаёт EventData и отправляет через dispatchEvent.
type TaskResultEvent ¶
type TaskResultEvent struct {
Type string `json:"type"`
Name string `json:"name"`
Transaction string `json:"transaction,omitempty"`
Data interface{} `json:"data"`
Error *APIError `json:"error"`
}
TaskResultEvent содержит результат фоновой задачи
type WebSocketBroadcaster ¶
type WebSocketBroadcaster interface {
BroadcastEvent(event interface{})
}
WebSocketBroadcaster интерфейс для отправки событий через WebSocket