feat: 初始化 Wails + React + Go 桌面应用模板
- Wails v2.16.0 + React 19 + TypeScript + Vite 7 - 插件系统(build tag 控制编译,plugin.json 运行时配置) - 支付插件(授权、账号、订单、退款、账单) - 高并发基础设施(任务池、批量处理器、限流器、环形缓冲、管道) - Windows 系统托盘(Win32 API) - CodeGraph 索引 + .memory 记忆包 - 默认图标 assets/icon.png
This commit is contained in:
54
internal/plugins/payment_impl.go
Normal file
54
internal/plugins/payment_impl.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Package plugins — payment 插件实现(带 build tag,未启用时不编译)
|
||||
//go:build payment
|
||||
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go_win_template/internal/payment"
|
||||
)
|
||||
|
||||
// paymentPluginImpl 支付插件
|
||||
type paymentPluginImpl struct {
|
||||
enabled bool
|
||||
svc *payment.Service
|
||||
}
|
||||
|
||||
func (p *paymentPluginImpl) Name() string { return "payment" }
|
||||
func (p *paymentPluginImpl) Enabled() bool { return p.enabled }
|
||||
func (p *paymentPluginImpl) Init(ctx context.Context) error {
|
||||
cfg, _ := LoadOrDefault()
|
||||
pcfg := payment.Config{
|
||||
AppID: getStringParam(cfg, "payment", "app_id"),
|
||||
MchID: getStringParam(cfg, "payment", "mch_id"),
|
||||
APIKey: getStringParam(cfg, "payment", "api_key"),
|
||||
BaseURL: getStringParam(cfg, "payment", "base_url"),
|
||||
AutoRefreshToken: true,
|
||||
}
|
||||
p.svc = payment.NewService(pcfg)
|
||||
fmt.Printf("[payment] initialized, base_url=%s\n", pcfg.BaseURL)
|
||||
return nil
|
||||
}
|
||||
func (p *paymentPluginImpl) Register(app *App) error { return nil }
|
||||
func (p *paymentPluginImpl) Shutdown() error { return nil }
|
||||
|
||||
// GetPaymentService 返回支付服务(any 类型,供 App 层类型断言)
|
||||
func (p *paymentPluginImpl) GetPaymentService() any {
|
||||
return p.svc
|
||||
}
|
||||
|
||||
func init() {
|
||||
cfg, _ := LoadOrDefault()
|
||||
Register(&paymentPluginImpl{enabled: cfg.Plugins["payment"].Enabled})
|
||||
}
|
||||
|
||||
func getStringParam(cfg *Config, plugin, key string) string {
|
||||
if opts, ok := cfg.Plugins[plugin]; ok {
|
||||
if v, ok := opts.Params[key].(string); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user