proxy

package
v0.0.0-...-bd8c593 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2020 License: MIT Imports: 1 Imported by: 0

README

什么是代理模式

代理模式:在不改变原始类的前提下,引入一个代理类给原始类增强功能。代理模式减少类对原始类代码的侵入(可以做到零侵入),实现框架和业务逻辑解耦。

代理模式的使用场景

非功能需求:鉴权、监控、统计、限流、日志、镜像流量、缓存

代理模式的三种实现方式

  1. 基于继承的代理(静态代理)
  2. 基于组合的代理(静态代理)
  3. 动态代理 (TODO)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IUserLogin

type IUserLogin interface {
	// contains filtered or unexported methods
}

定义接口

type UserLogin

type UserLogin struct{}

UserLogin是要被代理的类,它需要加入一些额外的功能,比如缓存、鉴权等非业务核心逻辑相关的功能,可以交给代理类实现

type UserLoginProxy1

type UserLoginProxy1 struct {
	UserLogin
}

UserLoginProxy1 基于继承的方式的代理。由于Go没有继承的,因此可以使用嵌入的方式模拟继承

type UserLoginProxy2

type UserLoginProxy2 struct {
	// contains filtered or unexported fields
}

基于组合的代理模式

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL