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

推荐订阅源

IT之家
IT之家
NISL@THU
NISL@THU
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tenable Blog
Forbes - Security
Forbes - Security
V2EX - 技术
V2EX - 技术
Webroot Blog
Webroot Blog
Schneier on Security
Schneier on Security
T
The Exploit Database - CXSecurity.com
T
Tor Project blog
C
Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
O
OpenAI News
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
D
Docker
AI
AI
Blog — PlanetScale
Blog — PlanetScale
S
Security @ Cisco Blogs
S
Schneier on Security
The GitHub Blog
The GitHub Blog
W
WeLiveSecurity
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
C
Check Point Blog
A
About on SuperTechFans
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Engineering at Meta
Engineering at Meta
I
InfoQ
T
Threat Research - Cisco Blogs
Project Zero
Project Zero
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
Cisco Talos Blog
Cisco Talos Blog
L
Lohrmann on Cybersecurity
S
Securelist

博客园 - ®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 go: Reactor 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: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: Proxy Pattern
®Geovin Du D · 2026-04-21 · via 博客园 - ®Geovin Du Dream Park™

项目结构:

image

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Proxy 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/4/21 20:26
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : errors.go
*/
package common

import "errors"

var ErrAccessDenied = errors.New("权限不足:非VIP顾客无法查看高端珠宝")
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Proxy 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/4/21 20:27
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry.go
*/
package api

// LuxuryJewelry 高端珠宝统一接口
type LuxuryJewelry interface {
	Display() error
	GetName() string
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Proxy 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/4/21 20:27
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry.go
*/
package domain

import "fmt"

// DiamondNecklace 钻石项链
type DiamondNecklace struct {
	name    string
	price   float64
	quality string
	crafts  string
}

func NewDiamondNecklace() *DiamondNecklace {
	return &DiamondNecklace{
		name:    "海洋之心典藏钻石项链",
		price:   12800000,
		quality: "VVS1 无瑕级",
		crafts:  "法国手工微镶",
	}
}

func (d *DiamondNecklace) Display() error {
	fmt.Printf("\n【核心珠宝展示】\n")
	fmt.Printf("品名:%s\n", d.name)
	fmt.Printf("价值:%.0f 元\n", d.price)
	fmt.Printf("品质:%s\n", d.quality)
	fmt.Printf("工艺:%s\n", d.crafts)
	return nil
}

func (d *DiamondNecklace) GetName() string {
	return d.name
}

// RubyRing 红宝石戒指
type RubyRing struct {
	name  string
	price float64
	color string
}

func NewRubyRing() *RubyRing {
	return &RubyRing{
		name:  "缅甸鸽血红宝石戒指",
		price: 6800000,
		color: "鸽血红",
	}
}

func (r *RubyRing) Display() error {
	fmt.Printf("\n【核心珠宝展示】\n")
	fmt.Printf("品名:%s\n", r.name)
	fmt.Printf("价值:%.0f 元\n", r.price)
	fmt.Printf("色级:%s\n", r.color)
	return nil
}

func (r *RubyRing) GetName() string {
	return r.name
}



/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Proxy 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/4/21 20:28
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : customer.go
*/
package domain

// Customer 顾客实体
type Customer struct {
	ID       string
	Level    string // VIP / NORMAL
	RealName string
}
/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Proxy 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/4/21 20:27
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : jewelry_proxy.go
*/
package proxy

import (
	"fmt"
	"godesginpattern/proxy/api"
	"godesginpattern/proxy/common"
	"godesginpattern/proxy/domain"
	"time"
)

// AccessLog 访问日志
type AccessLog struct {
	CustomerID  string
	JewelryName string
	VisitTime   time.Time
	Success     bool
	Message     string
}

// JewelryProxy 珠宝代理
type JewelryProxy struct {
	realJewelry api.LuxuryJewelry
	customer    *domain.Customer
}

func NewJewelryProxy(realJewelry api.LuxuryJewelry, customer *domain.Customer) *JewelryProxy {
	return &JewelryProxy{
		realJewelry: realJewelry,
		customer:    customer,
	}
}

// 权限校验
func (p *JewelryProxy) checkPermission() error {
	if p.customer.Level != "VIP" {
		return common.ErrAccessDenied
	}
	fmt.Printf("[权限校验] ✅ 顾客 %s(%s) 权限通过\n", p.customer.RealName, p.customer.ID)
	return nil
}

// 记录日志
func (p *JewelryProxy) recordLog(success bool, msg string) {
	log := AccessLog{
		CustomerID:  p.customer.ID,
		JewelryName: p.realJewelry.GetName(),
		VisitTime:   time.Now(),
		Success:     success,
		Message:     msg,
	}
	fmt.Printf("[访问日志] 📝 记录:%v\n", log)
}

// 安全保护
func (p *JewelryProxy) securityProtect() {
	fmt.Println("[安全保护] 🔒 珠宝已开启红外防盗 + 全程监控")
}

// Display 实现统一接口
func (p *JewelryProxy) Display() error {
	if err := p.checkPermission(); err != nil {
		p.recordLog(false, err.Error())
		return err
	}

	p.securityProtect()

	err := p.realJewelry.Display()
	if err != nil {
		p.recordLog(false, "展示失败:"+err.Error())
		return err
	}

	p.recordLog(true, "展示成功")
	fmt.Println("\n---------------------------------------")
	return nil
}

调用:

/*
# 版权所有  2026 ©涂聚文有限公司™ ®
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:Proxy 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/4/21 20:31
# User      :  geovindu
# Product   : GoLand
# Project   : godesginpattern
# File      : proxybll.go

proxy/
├── go.mod
├── main.go               # 入口:组装依赖、启动
├── api/
│   └── jewelry.go        # 接口层:统一契约定义
├── domain/
│   ├── jewelry.go        # 领域:真实珠宝对象
│   └── customer.go       # 领域:顾客模型
├── proxy/
│   └── jewelry_proxy.go  # 代理层:访问控制、日志、安全
└── common/

	└── errors.go         # 公共错误定义
*/
package bll

import (
	"godesginpattern/proxy/domain"
	"godesginpattern/proxy/proxy"
)

func ProxyMain() {
	println("========== 高端珠宝展厅(企业级代理模式) ==========\n")

	// 顾客
	vip := &domain.Customer{ID: "VIP_001", Level: "VIP", RealName: "张先生"}
	normal := &domain.Customer{ID: "CUS_002", Level: "NORMAL", RealName: "李先生"}

	// 真实珠宝
	necklace := domain.NewDiamondNecklace()
	ring := domain.NewRubyRing()

	// 代理
	p1 := proxy.NewJewelryProxy(necklace, vip)
	p2 := proxy.NewJewelryProxy(ring, vip)
	p3 := proxy.NewJewelryProxy(necklace, normal)

	// 调用
	_ = p1.Display()
	_ = p2.Display()
	_ = p3.Display()
}

输出:

image

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