Patterns / Structural patterns
image

import (
    "fmt"
)

//Graphic is Subject
type Graphic interface {
    Draw()
}

//Image is RealSubjec
type Image struct {
    FileName string
}

//Draw is Request()
func (im ImageDraw() {
    fmt.Println("draw " + im.FileName)
}

//ImageProxy is Proxy
type ImageProxy struct {
    FileName string
    _image   *Image
}

//GetImage creates an Subject
func (ip ImageProxyGetImage() *Image {
    if ip._image == nil {
        ip._image = &Image{ip.FileName}
    }
    return ip._image
}

//Draw is Request()
func (ip ImageProxyDraw() {
    ip.GetImage().Draw()
}

//Client
proxy := ImageProxy{FileName: "1.png"}
//operation without creating a RealSubject
fileName := proxy.FileName
//forwarded to the RealSubject
proxy.Draw()

fmt.Println(fileName)


Provide a surrogate or placeholder for another object to control access to it. The proxy implements the interface of the original object.