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
- func BuildFullID(pluginName, uiID string) string
- func DefaultAuthMethod(uiType string) string
- func DefaultShell(uiType string) string
- func GenerateMenuItems(uis []PluginUI) map[string][]map[string]any
- func IsValidShell(s string) bool
- func IsValidUIType(t string) bool
- func RegisterUIRoutes(eng *gin.Engine, repo *Repository, caller PluginCaller, ...) error
- func UISpecToConfig(spec interface{}) (*json.RawMessage, error)
- func ValidDataScopes() []string
- func ValidNavPositions() []string
- func ValidShells() []string
- func ValidUITypes() []string
- type PluginCaller
- type PluginUI
- type Repository
- func (r *Repository) Create(u *PluginUI, userID int) (int64, error)
- func (r *Repository) Delete(id int64) error
- func (r *Repository) GetByFullID(fullID string) (*PluginUI, error)
- func (r *Repository) GetByID(id int64) (*PluginUI, error)
- func (r *Repository) List(pluginName, uiType string, enabledOnly bool) ([]PluginUI, error)
- func (r *Repository) ListActive() ([]PluginUI, error)
- func (r *Repository) SetEnabled(id int64, enabled bool, userID int) error
- func (r *Repository) Update(u *PluginUI, userID int) error
- func (r *Repository) UpdateAdminOverrides(id int64, customDomain *string, branding *UIBrandingConfig, userID int) (*PluginUI, error)
- type TemplateRenderer
- type UIAuth
- type UIAuthConfig
- type UIBrandingConfig
- type UIConfig
- type UIInfoLookup
- type UINavConfig
- type UINavItemConfig
- type UIPWAConfig
- type UIRouteConfig
Constants ¶
const ( TypeAdminPage = "admin_page" TypeAgentApp = "agent_app" TypeCustomerApp = "customer_app" TypePublicPage = "public_page" TypeKiosk = "kiosk" )
UI types.
const ( ShellNone = "none" ShellMinimal = "minimal" ShellStandard = "standard" )
Shell types.
const ( AuthSession = "session" AuthToken = "token" AuthNone = "none" )
Auth methods. session and token both authenticate the caller (session cookie, Bearer JWT or API token); none leaves the UI public.
const ( ScopeSelf = "self" ScopeOrg = "org" ScopeAll = "all" )
Data scopes.
const ( )
Nav positions.
const DefaultPublicRateLimit = 60
DefaultPublicRateLimit is the per-client request budget (requests per minute) of a public plugin UI whose rate_limit is unset.
Variables ¶
This section is empty.
Functions ¶
func BuildFullID ¶
BuildFullID constructs the full ID from plugin name and UI ID.
func DefaultAuthMethod ¶
DefaultAuthMethod returns the default auth method for a UI type.
func DefaultShell ¶
DefaultShell returns the default shell for a UI type.
func GenerateMenuItems ¶
GenerateMenuItems converts active plugin UIs into MenuItemSpecs for navigation injection. Returns items grouped by location: "admin", "agent", "customer".
func IsValidShell ¶
IsValidShell checks whether the given shell type is supported.
func IsValidUIType ¶
IsValidUIType checks whether the given UI type is supported.
func RegisterUIRoutes ¶
func RegisterUIRoutes(eng *gin.Engine, repo *Repository, caller PluginCaller, renderer TemplateRenderer, auth UIAuth, 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. A UI whose config or auth settings cannot be honoured is logged and left unregistered; the other UIs still register.
func UISpecToConfig ¶
func UISpecToConfig(spec interface{}) (*json.RawMessage, error)
UISpecToConfig converts a plugin UISpec to the stored JSON config.
func ValidDataScopes ¶
func ValidDataScopes() []string
ValidDataScopes returns all supported data scopes.
func ValidNavPositions ¶
func ValidNavPositions() []string
ValidNavPositions returns all supported nav positions.
Types ¶
type PluginCaller ¶
type PluginCaller interface {
Call(ctx context.Context, pluginName, fn string, args []byte) ([]byte, 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) ParsedConfig ¶
ParsedConfig returns the full UISpec config from the JSON column.
func (*PluginUI) SetBranding ¶
func (u *PluginUI) SetBranding(branding *UIBrandingConfig) error
SetBranding merges administrator-managed branding overrides into the stored UI config.
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.
func (*Repository) UpdateAdminOverrides ¶
func (r *Repository) UpdateAdminOverrides(id int64, customDomain *string, branding *UIBrandingConfig, userID int) (*PluginUI, error)
UpdateAdminOverrides updates administrator-managed presentation settings.
type TemplateRenderer ¶
TemplateRenderer is the interface for rendering pongo2 templates.
type UIAuth ¶ added in v0.10.0
type UIAuth struct {
// Authenticate identifies the caller from a session cookie, JWT or API
// token and rejects anonymous requests.
Authenticate gin.HandlerFunc
// RequireGroup returns middleware admitting admins and members of the
// named agent group.
RequireGroup func(name string) gin.HandlerFunc
// Envelope replaces any client-supplied envelope key in args with the
// host's call envelope for the request's caller (identity, admin flag,
// organisation, language), the same envelope every API plugin call
// carries. The plugin Manager turns it into the call context. Required.
Envelope func(c *gin.Context, args map[string]any, pluginName string)
}
UIAuth carries the API layer's auth middlewares and call envelope into UI registration (this package cannot import internal/api).
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"`
Logo string `json:"logo,omitempty"`
Favicon string `json:"favicon,omitempty"`
Color string `json:"color,omitempty"`
}
UIBrandingConfig holds per-UI branding overrides.
func (*UIBrandingConfig) Clean ¶
func (b *UIBrandingConfig) Clean() *UIBrandingConfig
Clean trims string fields and returns a normalized branding config.
func (*UIBrandingConfig) IsZero ¶
func (b *UIBrandingConfig) IsZero() bool
IsZero reports whether no branding override is set.
type UIConfig ¶
type UIConfig struct {
Routes []UIRouteConfig `json:"routes,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 UIInfoLookup ¶ added in v0.10.0
UIInfoLookup resolves plugin UI rows (used for cross-UI nav gating).
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.