options_pattern

package
v0.0.0-...-eb36113 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connect

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

选项模式有很多优点,例如:支持传递多个参数,并且在参数发生变化时保持兼容性; 支持任意顺序传递参数;支持默认值;方便扩展;通过 WithXXX 的函数命名,可以使参数意义更加明确 结构体参数很多,创建结构体时,我们期望创建一个携带默认值的结构体变量,并选择性修改其中一些参数的值。 结构体参数经常变动,变动时我们又不想修改创建实例的函数。例如:结构体新增一个 retry 参数, 但是又不想在 NewConnect 入参列表中添加retry int这样的参数声明。

func NewConnec

func NewConnec(addr string, opts ...Option) (*Connect, error)

type Connection

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

func NewConnect

func NewConnect(addr string, opts *ConnectionOptions) (*Connection, error)

type Connection1

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

func NewConnect1

func NewConnect1(addr string) (*Connection1, error)

func NewConnectWithOptions

func NewConnectWithOptions(addr string, cache bool, time time.Duration) (*Connection1, error)

type ConnectionOptions

type ConnectionOptions struct {
	Caching bool
	Timeout time.Duration
}

func NewDefaultOptions

func NewDefaultOptions() *ConnectionOptions

type Option

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

func WithCaching

func WithCaching(cache bool) Option

func WithTimeOut

func WithTimeOut(t time.Duration) Option

Jump to

Keyboard shortcuts

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