123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package toolkit
- import (
- "time"
- "github.com/go-kit/kit/log"
- consulsd "github.com/go-kit/kit/sd/consul"
- consulapi "github.com/hashicorp/consul/api"
- )
- // ServiceOptions server options
- type ServiceOptions struct {
- // Address is the address of the Consul server
- Address string
- // Scheme is the URI scheme for the Consul server
- Scheme string
- // Datacenter to use. If not provided, the default agent datacenter is used.
- Datacenter string
- // Transport is the Transport to use for the http client.
- //Transport *http.Transport
- // HttpClient is the client to use. Default will be
- // used if not provided.
- //HttpClient *http.Client
- // HttpAuth is the auth info to use for http access.
- //HttpAuth *HttpBasicAuth
- // WaitTime limits how long a Watch will block. If not provided,
- // the agent default values will be used.
- WaitTime time.Duration
- // Token is used to provide a per-request ACL token
- // which overrides the agent's default token.
- Token string
- //TLSConfig TLSConfig
- }
- // NewConsulInstancer consul Instancer
- func NewConsulInstancer(options ServiceOptions, name string, tags []string, passingOnly bool, logger log.Logger) (instancer *consulsd.Instancer, err error) {
- var client consulsd.Client
- config := consulapi.DefaultConfig()
- config.Address = options.Address
- config.Scheme = options.Scheme
- config.Datacenter = options.Datacenter
- config.WaitTime = options.WaitTime
- config.Token = options.Token
- consulClient, err := consulapi.NewClient(config)
- if err != nil {
- //logger.Log("err", err)
- return
- }
- client = consulsd.NewClient(consulClient)
- instancer = consulsd.NewInstancer(client, logger, name, tags, passingOnly)
- return
- }
|