mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
c9b702d234
Architecture: - Move GetFromContext/SetToContext from plugins/domain/auth to pkg/util - Move auth context key constants to core/contracts (AuthUserObjKey, AuthTokenAuthKey, etc.) - Add AuthUserIDKey, AuthUserNameKey, GetCurrentUserID, RevokeToken to contracts.AuthService - All 4 domain plugin Apply() methods now resolve AuthService via core.Using IoC - Plugin route middleware uses authSvc.RequireAuthMiddleware() cast to gin.HandlerFunc - DisallowTokenAuth added to AuthService contract Migration: - Replace cmd/app.go SetMigrationRunner bridge with gooseEngine implementing core.MigrationEngine - Remove cmd/root.go PreRun migration hooks and runMigrations() function - Migrations now run via core.App.Start() → RunMigrations() Events: - Add complete domain event topic catalog and payload DTOs to core/contracts/events.go - 15 event topics across auth, user, admin, upload, message_gateway, risk_control Downstream: - Create downstream/ directory with README and custom_example plugin scaffold CI: - Update Makefile code-check architecture guards for Cordis layering - Enforce: core no gin/gorm/asynq, contracts no plugins/, pkg no plugins/, domain no cross-domain
48 lines
1.4 KiB
Go
48 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 (
|
|
"github.com/Rain-kl/Wavelet/core"
|
|
"github.com/Rain-kl/Wavelet/core/contracts"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 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(401, gin.H{"error": "unauthorized"})
|
|
return
|
|
}
|
|
c.JSON(200, gin.H{"message": "Hello " + user.Username})
|
|
})
|
|
|
|
return nil
|
|
} |