Functional Options
Functional options are a method of implementing clean/eloquent APIs in Go. Options implemented as a function set the state of that option.
...We have a client code that expects some features of an object (Lightning port), but we have another object called adaptee (Windows laptop) which offers the same functionality but through a different interface (USB port)
This is where the Adapter pattern comes into the picture. We create a struct type known as adapter that will:
Refer to https://swsmile.info/post/design-pattern-adapter-pattern/ for Adapter pattern.
...The object pool creational design pattern is used to prepare and keep multiple instances according to the demand expectation.
As and when needed, a client can request an object from the pool, use it, and return it to the pool. The object in the pool is never destroyed.
Refer to https://swsmile.info/post/design-pattern-flyweight-pattern/#%E4%BA%AB%E5%85%83%E6%A8%A1%E5%BC%8F%E7%9A%84%E5%B9%BF%E6%B3%9B%E4%BD%BF%E7%94%A8 for Flyweight pattern.
...Abstract Factory Design Pattern is a creational design pattern that lets you create a family of related objects. It is an abstraction over the factory pattern.
Refer to https://swsmile.info/post/design-pattern-factory-pattern/ for Factory pattern.
...https://en.wikipedia.org/wiki/Context_switch
虽然线程比较轻量,但是在调度时也有比较大的额外开销。每个线程会都占用 1M 以上的内存空间,在切换线程时不止会消耗较多的内存,恢复寄存器中的内容还需要向操作系统申请或者销毁资源,每一次线程上下文的切换都需要消耗 ~1us 左右的时间,但是 Go 调度器对 Goroutine 的上下文切换约为 ~0.2us,减少了 80% 的额外开销。
...