Files
OpenFlare/plugins/domain/system/plugin.go
T
ryan 416603b616 fix(persistence): migrate all pkg/persistence imports to plugins/infra/database and plugins/infra/cache
- Replace db.DB(ctx) with database.DB(ctx) from plugins/infra/database
- Replace db.Redis/db.PrefixedKey/db.GetJSON/db.SetJSON with cachepkg.* from plugins/infra/cache
- Replace pkg/persistence/idgen with pkg/idgen (already exists)
- Replace pkg/persistence/batchwriter with pkg/batchwriter (already exists)
- Replace pkg/persistence/migrator with pkg/migrator (already exists)
- Replace pkg/persistence/logstore with plugins/domain/risk_control/logstore
- Delete defunct pkg/{persistence,cap,message_gateway,push,shared,task}
- Fix vet issues: db alias in domain_test.go, driver_asynq_worker.TaskHandler reference
- Update Makefile architecture guard
- Update docs and skill references
- Update go.mod: gorilla/sessions promotion to direct dependency
2026-08-28 10:59:24 +08:00

73 lines
1.9 KiB
Go

// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
// Package system provides core system health probes, public config endpoints, and static frontend assets dispatch plugin for Cordis.
package system
import (
"net/http"
"github.com/Rain-kl/Wavelet/core"
"github.com/Rain-kl/Wavelet/pkg/config"
database "github.com/Rain-kl/Wavelet/plugins/infra/database"
"github.com/Rain-kl/Wavelet/pkg/response"
"github.com/gin-gonic/gin"
)
// Plugin implements core.Plugin to provide system-level basic routes.
type Plugin struct{}
// New creates a new system domain plugin.
func New() *Plugin {
return &Plugin{}
}
// Name returns the unique identifier for the system domain plugin.
func (p *Plugin) Name() string {
return "system"
}
// Manifest returns the plugin metadata.
func (p *Plugin) Manifest() core.Manifest {
return core.Manifest{
Name: "system",
Version: "1.0.0",
Description: "System health check, public config, and assets domain plugin",
Author: "Wavelet Team",
}
}
// Apply registers system routes.
func (p *Plugin) Apply(ctx *core.Context) error {
// 1. Health check
ctx.Router().GET("/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
ctx.Router().GET("/api/healthz", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
// 2. Public config
ctx.Router().GET("/api/v1/config/public", func(c *gin.Context) {
type configItem struct {
Key string `json:"key"`
Value string `json:"value"`
}
var configs []configItem
_ = database.DB(c.Request.Context()).Table("w_system_configs").Where("visibility = ?", "visible").Find(&configs).Error
c.JSON(http.StatusOK, response.OK(gin.H{
"configs": configs,
"app": gin.H{
"name": config.Config.App.AppName,
},
}))
})
// 3. Custom injection
ctx.Router().GET("/custom", func(c *gin.Context) {
c.JSON(http.StatusOK, response.OK(gin.H{"custom": true}))
})
return nil
}