2
0
Files
gitcaddy-server/modules/plugins/plugin.go
logikonline b91b9c5711
Some checks failed
Build and Release / Create Release (push) Successful in 0s
Build and Release / Lint (push) Failing after 4m23s
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Integration Tests (PostgreSQL) (push) Has been cancelled
Build and Release / Unit Tests (push) Has been cancelled
feat: implement plugin loading system
- Add modules/plugins/loader.go to load .so plugins from plugins directory
- Add modules/setting/plugins.go for [plugins] configuration section
- Wire up plugin loading before DB init so plugins can register models
- Wire up plugin migrations and initialization after DB init
- Register plugin routes in web.go

Plugins can now be loaded at runtime by placing .so files in the plugins
directory and enabling [plugins] ENABLED = true in app.ini.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 10:16:42 -05:00

91 lines
2.4 KiB
Go

// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT
package plugins
import (
"context"
"xorm.io/xorm"
)
// Plugin defines the interface that all GitCaddy plugins must implement
type Plugin interface {
// Name returns the unique identifier for this plugin
Name() string
// Version returns the plugin version
Version() string
// Description returns a human-readable description
Description() string
// Init is called when the plugin is loaded
Init(ctx context.Context) error
// Shutdown is called when the server is shutting down
Shutdown(ctx context.Context) error
}
// DatabasePlugin is implemented by plugins that need database tables
type DatabasePlugin interface {
Plugin
// RegisterModels returns the models to be registered with the database
RegisterModels() []any
// Migrate runs any database migrations for this plugin
Migrate(ctx context.Context, x *xorm.Engine) error
}
// WebRoutesPlugin is implemented by plugins that add web UI routes
type WebRoutesPlugin interface {
Plugin
// RegisterWebRoutes adds routes to the web UI router
// The router is a *web.Router from the gitcaddy server
RegisterWebRoutes(m any)
}
// APIRoutesPlugin is implemented by plugins that add API routes
type APIRoutesPlugin interface {
Plugin
// RegisterAPIRoutes adds routes to the API router
// The router is a *web.Router from the gitcaddy server
RegisterAPIRoutes(m any)
}
// RepoRoutesPlugin is implemented by plugins that add per-repository routes
type RepoRoutesPlugin interface {
Plugin
// RegisterRepoWebRoutes adds routes under /{owner}/{repo}/
// The router is a *web.Router from the gitcaddy server
RegisterRepoWebRoutes(m any)
// RegisterRepoAPIRoutes adds routes under /api/v1/repos/{owner}/{repo}/
// The router is a *web.Router from the gitcaddy server
RegisterRepoAPIRoutes(m any)
}
// LicensedPlugin is implemented by plugins that require a license
type LicensedPlugin interface {
Plugin
// ValidateLicense checks if the plugin is properly licensed
ValidateLicense(ctx context.Context) error
// LicenseInfo returns information about the current license
LicenseInfo() *LicenseInfo
}
// LicenseInfo contains license details
type LicenseInfo struct {
Valid bool
Tier string // e.g., "solo", "pro", "team", "enterprise"
CustomerID string
ExpiresAt int64
GracePeriod bool // true if in grace period after expiry
}