Documentation ¶
Overview ¶
This package provides Consul dynamic data-source implementation for Sentinel.
Example (ConsulDataSource_CustomizeClient) ¶
client, err := api.NewClient(&api.Config{ Address: "127.0.0.1:8500", }) if err != nil { fmt.Println("Failed to instance consul client") os.Exit(1) } ds, err := NewDataSource("property_key", // customize consul client WithConsulClient(client), // preset property handlers WithPropertyHandlers(), // reset queryOptions, defaultQueryOptions as default WithQueryOptions(&api.QueryOptions{}), ) if err != nil { fmt.Println("Failed to instance consul datasource") os.Exit(1) } if err := ds.Initialize(); err != nil { fmt.Println("Failed to initialize consul datasource") os.Exit(1) }
Output:
Example (ConsulDataSource_CustomizeConfig) ¶
ds, err := NewDataSource("property_key", // customize consul config WithConsulConfig(&api.Config{ Address: "127.0.0.1:8500", }), // preset property handlers WithPropertyHandlers(), // reset queryOptions, defaultQueryOptions as default WithQueryOptions(&api.QueryOptions{ WaitIndex: 0, // override default WaitTime(5min) WaitTime: time.Second * 90, }), ) if err != nil { fmt.Println("Failed to instance consul datasource") os.Exit(1) } if err := ds.Initialize(); err != nil { fmt.Println("Failed to initialize consul datasource") os.Exit(1) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func NewDataSource ¶
func NewDataSource(propertyKey string, opts ...Option) (datasource.DataSource, error)
Types ¶
type Option ¶
type Option func(*options)
func WithConsulClient ¶
WithConsulClient injects consul client instance
func WithConsulConfig ¶
WithConsulConfig injects consul client config
func WithPropertyHandlers ¶
func WithPropertyHandlers(handlers ...datasource.PropertyHandler) Option
WithPropertyHandlers injects property handlers
func WithQueryOptions ¶
func WithQueryOptions(queryOptions *api.QueryOptions) Option
WithQueryOptions sets options for consulClient.Get method
Click to show internal directories.
Click to hide internal directories.