pluginui

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package pluginui implements the GoatKit PaaS Plugin UI System.

Plugins declare independent UIs (agent apps, customer portals, public pages, kiosks) via UISpec in GKRegistration. The platform handles routing, shells, auth, navigation, and PWA manifest generation.

Index

Constants

View Source
const (
	TypeAdminPage   = "admin_page"
	TypeAgentApp    = "agent_app"
	TypeCustomerApp = "customer_app"
	TypePublicPage  = "public_page"
	TypeKiosk       = "kiosk"
)

UI types.

View Source
const (
	ShellNone     = "none"
	ShellMinimal  = "minimal"
	ShellStandard = "standard"
)

Shell types.

View Source
const (
	AuthSession = "session"
	AuthPIN     = "pin"
	AuthToken   = "token"
	AuthNone    = "none"
)

Auth methods.

View Source
const (
	ScopeSelf = "self"
	ScopeOrg  = "org"
	ScopeAll  = "all"
)

Data scopes.

View Source
const (
	NavBottom = "bottom"
	NavTop    = "top"
	NavSide   = "side"
)

Nav positions.

Variables

This section is empty.

Functions

func BuildFullID

func BuildFullID(pluginName, uiID string) string

BuildFullID constructs the full ID from plugin name and UI ID.

func DefaultAuthMethod

func DefaultAuthMethod(uiType string) string

DefaultAuthMethod returns the default auth method for a UI type.

func DefaultShell

func DefaultShell(uiType string) string

DefaultShell returns the default shell for a UI type.

func GenerateMenuItems

func GenerateMenuItems(uis []PluginUI) map[string][]map[string]any

GenerateMenuItems converts active plugin UIs into MenuItemSpecs for navigation injection. Returns items grouped by location: "admin", "agent", "customer".

func IsValidShell

func IsValidShell(s string) bool

IsValidShell checks whether the given shell type is supported.

func IsValidUIType

func IsValidUIType(t string) bool

IsValidUIType checks whether the given UI type is supported.

func RegisterUIRoutes

func RegisterUIRoutes(eng *gin.Engine, repo *Repository, caller PluginCaller, renderer TemplateRenderer, logger *slog.Logger) error

RegisterUIRoutes registers all active plugin UI routes on the given gin engine. Call this during dynamic engine rebuild, after YAML routes and before plugin routes.

func UISpecToConfig

func UISpecToConfig(spec interface{}) (*json.RawMessage, error)

UISpecToConfig converts a plugin UISpec to the stored JSON config.

func ValidAuthMethods

func ValidAuthMethods() []string

ValidAuthMethods returns all supported auth methods.

func ValidDataScopes

func ValidDataScopes() []string

ValidDataScopes returns all supported data scopes.

func ValidNavPositions

func ValidNavPositions() []string

ValidNavPositions returns all supported nav positions.

func ValidShells

func ValidShells() []string

ValidShells returns all supported shell types.

func ValidUITypes

func ValidUITypes() []string

ValidUITypes returns all supported UI types.

Types

type PluginCaller

type PluginCaller interface {
	Call(ctx context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
}

PluginCaller is an interface for calling plugin functions. Satisfied by the plugin.Manager.

type PluginUI

type PluginUI struct {
	ID           int64            `json:"id" db:"id"`
	PluginName   string           `json:"plugin_name" db:"plugin_name"`
	UIID         string           `json:"ui_id" db:"ui_id"`
	FullID       string           `json:"full_id" db:"full_id"`
	Name         string           `json:"name" db:"name"`
	Description  *string          `json:"description,omitempty" db:"description"`
	UIType       string           `json:"ui_type" db:"ui_type"`
	Shell        string           `json:"shell" db:"shell"`
	Icon         *string          `json:"icon,omitempty" db:"icon"`
	Config       *json.RawMessage `json:"config,omitempty" db:"config"`
	Enabled      bool             `json:"enabled" db:"enabled"`
	CustomDomain *string          `json:"custom_domain,omitempty" db:"custom_domain"`
	ValidID      int              `json:"valid_id" db:"valid_id"`
	CreateTime   time.Time        `json:"create_time" db:"create_time"`
	CreateBy     int              `json:"create_by" db:"create_by"`
	ChangeTime   time.Time        `json:"change_time" db:"change_time"`
	ChangeBy     int              `json:"change_by" db:"change_by"`
}

PluginUI represents a stored plugin UI from gk_plugin_ui.

func (*PluginUI) BasePath

func (u *PluginUI) BasePath() string

BasePath returns the URL path prefix for this UI: /ui/{full_id}/

func (*PluginUI) IsActive

func (u *PluginUI) IsActive() bool

IsActive returns true if this UI is valid and enabled.

func (*PluginUI) ParsedConfig

func (u *PluginUI) ParsedConfig() (*UIConfig, error)

ParsedConfig returns the full UISpec config from the JSON column.

type Repository

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

Repository provides CRUD operations for plugin UI registrations.

func NewRepository

func NewRepository() (*Repository, error)

NewRepository creates a repository using the global DB connection.

func NewRepositoryWithDB

func NewRepositoryWithDB(db *sql.DB) *Repository

NewRepositoryWithDB creates a repository with an explicit DB connection.

func (*Repository) Create

func (r *Repository) Create(u *PluginUI, userID int) (int64, error)

Create inserts a new plugin UI. Returns the new row ID.

func (*Repository) Delete

func (r *Repository) Delete(id int64) error

Delete removes a plugin UI permanently.

func (*Repository) GetByFullID

func (r *Repository) GetByFullID(fullID string) (*PluginUI, error)

GetByFullID retrieves a plugin UI by its full ID ({plugin}_{ui_id}).

func (*Repository) GetByID

func (r *Repository) GetByID(id int64) (*PluginUI, error)

GetByID retrieves a plugin UI by its database ID.

func (*Repository) List

func (r *Repository) List(pluginName, uiType string, enabledOnly bool) ([]PluginUI, error)

List retrieves plugin UIs with optional filters.

func (*Repository) ListActive

func (r *Repository) ListActive() ([]PluginUI, error)

ListActive returns all enabled, valid plugin UIs. Used at startup for route registration.

func (*Repository) SetEnabled

func (r *Repository) SetEnabled(id int64, enabled bool, userID int) error

SetEnabled enables or disables a plugin UI.

func (*Repository) Update

func (r *Repository) Update(u *PluginUI, userID int) error

Update updates an existing plugin UI.

type TemplateRenderer

type TemplateRenderer interface {
	HTML(c *gin.Context, code int, name string, data pongo2.Context)
}

TemplateRenderer is the interface for rendering pongo2 templates.

type UIAuthConfig

type UIAuthConfig struct {
	Method string   `json:"method,omitempty"` // session, pin, token, none
	Groups []string `json:"groups,omitempty"`
}

UIAuthConfig holds per-UI auth configuration.

type UIBrandingConfig

type UIBrandingConfig struct {
	AppName string `json:"app_name,omitempty"`
	Favicon string `json:"favicon,omitempty"`
	Color   string `json:"color,omitempty"`
}

UIBrandingConfig holds per-UI branding overrides.

type UIConfig

type UIConfig struct {
	Routes    []UIRouteConfig   `json:"routes,omitempty"`
	Nav       *UINavConfig      `json:"nav,omitempty"`
	Branding  *UIBrandingConfig `json:"branding,omitempty"`
	Auth      *UIAuthConfig     `json:"auth,omitempty"`
	PWA       *UIPWAConfig      `json:"pwa,omitempty"`
	DataScope string            `json:"data_scope,omitempty"`
	RateLimit int               `json:"rate_limit,omitempty"`
}

UIConfig stores the full UISpec configuration in the config JSON column.

type UINavConfig

type UINavConfig struct {
	Position string            `json:"position"` // bottom, top, side
	Items    []UINavItemConfig `json:"items"`
}

UINavConfig defines the navigation for a plugin UI.

type UINavItemConfig

type UINavItemConfig struct {
	Label string `json:"label"`
	Icon  string `json:"icon"`
	Path  string `json:"path"`
	Badge string `json:"badge,omitempty"` // plugin function name for badge count
	Order int    `json:"order,omitempty"`
}

UINavItemConfig is a navigation item.

type UIPWAConfig

type UIPWAConfig struct {
	Enabled     bool     `json:"enabled"`
	StartURL    string   `json:"start_url,omitempty"`
	Display     string   `json:"display,omitempty"` // standalone, fullscreen, minimal-ui
	ThemeColor  string   `json:"theme_color,omitempty"`
	CacheRoutes []string `json:"cache_routes,omitempty"`
}

UIPWAConfig holds PWA manifest configuration.

type UIRouteConfig

type UIRouteConfig struct {
	Path    string `json:"path"`
	Method  string `json:"method,omitempty"`
	Handler string `json:"handler"`
}

UIRouteConfig is a route within a plugin UI.

Jump to

Keyboard shortcuts

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