惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
罗磊的独立博客
博客园 - 聂微东
博客园_首页
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
量子位
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
月光博客
月光博客
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
H
Help Net Security
O
OpenAI News
Blog — PlanetScale
Blog — PlanetScale
S
Security Affairs
S
Security @ Cisco Blogs
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
AI
AI
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Schneier on Security
Cloudbric
Cloudbric
H
Heimdal Security Blog
J
Java Code Geeks
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
I
Intezer
GbyAI
GbyAI

博客园 - ®Geovin Du Dream Park™

go: Functional Options Pattern go:Timing Functions Pattern python: Timing Functions Pattern go: Steady-State Pattern python: Steady-State Pattern go: Handshaking Pattern python: Handshaking Pattern go: Fail-Fast Pattern python: Fail-Fast Pattern I go: Deadline Pattern python: Deadline Pattern go: Circuit-Breaker Pattern python: Circuit-Breaker Pattern go: Bulkheads Pattern python: Bulkheads Pattern go: Push & Pull Pattern python: Push & Pull Pattern python: Publish/Subscribe Pattern II go: Publish/Subscribe Pattern python: Publish/Subscribe Pattern go: Futures & Promises Pattern python: Futures & Promises Pattern go: Worker Pool Pattern go:Pipeline Pattern python: Worker Pool Pattern python: Pipeline Pattern go: Fan-Out Pattern python: Fan-Out Pattern go: Fan-In Pattern python: Fan-In Pattern Fan-In go: Producer Consumer  Pattern python: Producer Consumer Pattern go: Parallelism Pattern python: Parallelism Pattern python: Reactor Pattern go: Generators Pattern python: speech to text offline python: Generators Pattern go: Coroutines Pattern python:Coroutines Pattern go: Broadcast Pattern python: Broadcast Pattern python: Bounded Parallelism Pattern go: Bounded Parallelism Pattern python: N-Barrier Pattern go: N-Barrier Pattern python: Semaphore Pattern go: Semaphore Pattern python: Read-Write Lock Pattern go: Read-Write Lock Pattern python: Monitor Pattern go: Monitor Pattern python: Mutex Pattern go: Lock/Mutex Pattern Python: Condition Variable Pattern go:Condition Variable Pattern python: Registry Pattern python: Interpreter Pattern go: Interpreter Pattern go: Registry Pattern go: Memento Pattern go: Command Pattern go: State Pattern go:Template Method Pattern go: Strategy Pattern go: Visitor Pattern go: Observer Pattern go: Mediator Pattern go: Iterator Pattern go: Chain of Responsibility Pattern go: Proxy Pattern go:Decorator Pattern go: Facade Pattern go: Flyweight Pattern go: Composite Pattern go: Singleton Pattern go: Prototype Pattern go: Bridge Pattern go: Adapter Pattern go: Builder Pattern 密码进行加盐哈希 using CSharp,Python,Go,Java go: Abstract Factory Pattern go: Model,Interface,DAL ,Factory,BLL using mysql go: Simple Factory Pattern go: Factory Method Pattern go: goLang 在Windows环境搭建Go语言开发环境 CSharp: Parallel Extensions cpp: class python: 蝴蝶跟随鼠标 javascript: 中国历史人物热力分布图using echart javascript: 中国历史人物热力图 python: 初养龙虾微信纯文字自动回复using workBuddy python: object 入门 python: Factory Method Pattern python: Simple Factory Pattern python: Abstract Factory Pattern 区域化 代码 python: Null Object Pattern python: Builder Pattern python: Adapter Pattern
go: Reactor Pattern
®Geovin Du Dream Park™ · 2026-06-16 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Reactor  Pattern 反应器模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/16 20:22
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : common.go
*/
package common

import (
	"log"
	"os"
)

// 业务事件类型枚举
type BusinessEventType string

const (
	RAW_MATERIAL      BusinessEventType = "raw_material"
	PROCESS_CHECK     BusinessEventType = "process_check"
	STORE_SALE        BusinessEventType = "sale"
	AFTER_SALE_REPAIR BusinessEventType = "repair"
	INVENTORY_CHECK   BusinessEventType = "inventory"
)

// 统一日志
func GetReactorLogger(name string) *log.Logger {
	return log.New(os.Stdout, "["+name+"] ", log.Ldate|log.Ltime)
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Reactor  Pattern 反应器模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/16 20:22
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : event.go
*/
package event

import "godesginpattern/reactor/common"

// 业务事件实体(对齐 Python dataclass)
type BusinessEvent struct {
	EventType common.BusinessEventType
	Payload   map[string]interface{}
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Reactor  Pattern 反应器模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/16 20:23
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : handler.go
*/
package handler

import (
	"godesginpattern/reactor/common"
	"godesginpattern/reactor/event"
)

var logger = common.GetReactorLogger("handler")

// 原料采购
type MaterialHandler struct{}

func (h *MaterialHandler) Handle(e event.BusinessEvent) {
	p := e.Payload
	logger.Printf("【原料采购验收】原料:%s | 纯度:%s | 重量:%vg",
		p["material_type"], p["purity"], p["weight"])
	logger.Printf("%s 原料验收合格,入库完成!", p["material_type"])
}

// 加工质检
type ProcessHandler struct{}

func (h *ProcessHandler) Handle(e event.BusinessEvent) {
	p := e.Payload
	logger.Printf("【珠宝加工质检】款式:%s | 证书:%s | 工艺:%s",
		p["style"], p["cert_no"], p["craft"])
	logger.Printf("%s 工艺合格,证书合规,成品入库!", p["style"])
}

// 销售结算
type SaleHandler struct{}

func (h *SaleHandler) Handle(e event.BusinessEvent) {
	p := e.Payload
	price := p["unit_price"].(int)
	qty := p["quantity"].(int)
	total := price * qty
	logger.Printf("【门店销售结算】商品:%s | 单价:%v元 | 数量:%v件",
		p["product_name"], price, qty)
	logger.Printf("订单%s 结算总价:%v元,销售完成!", p["order_id"], total)
}

// 售后维修
type RepairHandler struct{}

func (h *RepairHandler) Handle(e event.BusinessEvent) {
	p := e.Payload
	logger.Printf("【售后维修】客户:%s | 饰品:%s | 项目:%s",
		p["customer_name"], p["jewelry_name"], p["repair_item"])
	logger.Printf("%s 完成,可领取珠宝!", p["repair_item"])
}

// 库存盘点
type InventoryHandler struct{}

func (h *InventoryHandler) Handle(e event.BusinessEvent) {
	p := e.Payload
	logger.Printf("【库存盘点】类型:%s | 总数:%v | 总价值:%v万元",
		p["inventory_type"], p["total_num"], p["total_value"])
	logger.Println("盘点结果:账实相符,库存更新完成!")
}


/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Reactor  Pattern 反应器模式
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/16 20:24
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : reactor.go
*/
package reactors

import (
	"godesginpattern/reactor/common"
	"godesginpattern/reactor/event"
	"godesginpattern/reactor/handler"
)

// 事件分离器 Demultiplexer
type EventDemultiplexer struct {
	handlerMap map[common.BusinessEventType]interface{ Handle(e event.BusinessEvent) }
}

func NewDemux() *EventDemultiplexer {
	return &EventDemultiplexer{
		handlerMap: make(map[common.BusinessEventType]interface{ Handle(e event.BusinessEvent) }),
	}
}
func (d *EventDemultiplexer) Register(t common.BusinessEventType, h interface{ Handle(e event.BusinessEvent) }) {
	d.handlerMap[t] = h
}
func (d *EventDemultiplexer) Get(t common.BusinessEventType) interface{ Handle(e event.BusinessEvent) } {
	return d.handlerMap[t]
}

// Reactor 核心
type JewelryReactor struct {
	demux *EventDemultiplexer
}

func NewJewelryReactor() *JewelryReactor {
	demux := NewDemux()
	demux.Register(common.RAW_MATERIAL, &handler.MaterialHandler{})
	demux.Register(common.PROCESS_CHECK, &handler.ProcessHandler{})
	demux.Register(common.STORE_SALE, &handler.SaleHandler{})
	demux.Register(common.AFTER_SALE_REPAIR, &handler.RepairHandler{})
	demux.Register(common.INVENTORY_CHECK, &handler.InventoryHandler{})

	return &JewelryReactor{demux: demux}
}

func (r *JewelryReactor) Dispatch(e event.BusinessEvent) {
	h := r.demux.Get(e.EventType)
	if h != nil {
		h.Handle(e)
	}
}

调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : goLang 2024.3.6 go 26.2
# os        : windows 10
# database  : mysql 9.0 sql server 2019, postgreSQL 17.0  Oracle 21c Neo4j
# Datetime  : 2026/6/16 20:25
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : reactorbll.go
*/
package bll

import (
	"godesginpattern/reactor/common"
	"godesginpattern/reactor/event"
	"godesginpattern/reactor/reactors"
)

var reactorlogger = common.GetReactorLogger("ReactorBll")

// ReactorBll 你要的封装类
type ReactorBll struct {
	reactor *reactors.JewelryReactor
}

func NewReactorBll() *ReactorBll {
	return &ReactorBll{
		reactor: reactors.NewJewelryReactor(),
	}
}

func ReactorMain(b *ReactorBll) {
	reactorlogger.Println("========== ReactorBll demo 开始 ==========")

	events := []event.BusinessEvent{
		{
			EventType: common.RAW_MATERIAL,
			Payload: map[string]interface{}{
				"material_type": "足金999",
				"purity":        "99.9%",
				"weight":        800,
			},
		},
		{
			EventType: common.PROCESS_CHECK,
			Payload: map[string]interface{}{
				"style":   "1克拉钻戒",
				"cert_no": "GIA987654321",
				"craft":   "微镶精工",
			},
		},
		{
			EventType: common.STORE_SALE,
			Payload: map[string]interface{}{
				"product_name": "古法金镯",
				"unit_price":   15680,
				"quantity":     1,
				"order_id":     "JEW20260615001",
			},
		},
		{
			EventType: common.AFTER_SALE_REPAIR,
			Payload: map[string]interface{}{
				"customer_name": "李女士",
				"jewelry_name":  "18K金项链",
				"repair_item":   "焊接+抛光",
			},
		},
		{
			EventType: common.INVENTORY_CHECK,
			Payload: map[string]interface{}{
				"inventory_type": "钻石成品",
				"total_num":      1680,
				"total_value":    12600,
			},
		},
	}

	for _, evt := range events {
		b.reactor.Dispatch(evt)
	}

	reactorlogger.Println("========== ReactorBll demo 结束 ==========")
}

输出:

image

哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)