mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
299ac30ee4
- Purify core micro-kernel by removing context hardcoded helpers and reverse dependencies - Eliminate init() side effects in infra plugins with reversible lifecycle disposal - Completely isolate plugins by removing cross-plugin imports and using core/contracts - Introduce TaskService and RiskControlService contracts for unified cross-plugin APIs - Regenerate Swagger documentation and update developer guide matrix - Achieve 0 violations in check_cordis_architecture.sh and 100% test pass
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package custom_example demonstrates how to build a downstream Cordis plugin.
|
|
// Copy this directory to create your own plugin.
|
|
package custom_example
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"Wavelet/core"
|
|
"Wavelet/core/contracts"
|
|
)
|
|
|
|
// Plugin implements core.Plugin for the custom_example downstream plugin.
|
|
type Plugin struct{}
|
|
|
|
// New creates a new custom_example plugin.
|
|
func New() *Plugin {
|
|
return &Plugin{}
|
|
}
|
|
|
|
// Name returns the unique identifier for this plugin.
|
|
func (p *Plugin) Name() string {
|
|
return "custom_example"
|
|
}
|
|
|
|
// Apply registers routes and services into the Cordis micro-kernel Context.
|
|
func (p *Plugin) Apply(ctx *core.Context) error {
|
|
// Resolve platform services via IoC container (no direct imports of domain plugins).
|
|
var authSvc contracts.AuthService
|
|
if err := core.Using[contracts.AuthService](ctx, func(svc contracts.AuthService) { authSvc = svc }); err != nil {
|
|
return err
|
|
}
|
|
_ = authSvc
|
|
|
|
// Register routes using the auth middleware obtained through the contract.
|
|
g := ctx.Router().Group("/api/v1/custom", authSvc.RequireAuthMiddleware().(gin.HandlerFunc))
|
|
g.GET("/hello", func(c *gin.Context) {
|
|
user, err := authSvc.GetCurrentUser(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"message": "Hello " + user.Username})
|
|
})
|
|
|
|
return nil
|
|
}
|