代理在计算机领域是个经常被提及的名词,如nginx就常被用于webf服务的代理。那么怎么实现代理这种模式?
package main
import "fmt"
type Subject interface {
Do() string
}
type RelSubject struct {
}
func (r *RelSubject) Do() string {
return "test"
}
type Proxy struct {
real RelSubject
}
func (proxy *Proxy) Do() string {
res := proxy.real.Do()
return res
}
func main() {
var sub Subject
sub = &Proxy{}
res := sub.Do()
fmt.Println(res)
}