...

Source file src/go.etcd.io/etcd/client/v3/naming/doc.go

Documentation: go.etcd.io/etcd/client/v3/naming

     1  // Copyright 2017 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package naming provides:
    16  //   - subpackage endpoints: an abstraction layer to store and read endpoints
    17  //     information from etcd.
    18  //   - subpackage resolver: an etcd-backed gRPC resolver for discovering gRPC
    19  //     services based on the endpoints configuration
    20  //
    21  // To use, first import the packages:
    22  //
    23  //	import (
    24  //		"go.etcd.io/etcd/client/v3"
    25  //		"go.etcd.io/etcd/client/v3/naming/endpoints"
    26  //		"go.etcd.io/etcd/client/v3/naming/resolver"
    27  //		"google.golang.org/grpc"
    28  //	)
    29  //
    30  // First, register new endpoint addresses for a service:
    31  //
    32  //	func etcdAdd(c *clientv3.Client, service, addr string) error {
    33  //		em := endpoints.NewManager(c, service)
    34  //		return em.AddEndpoint(c.Ctx(), service+"/"+addr, endpoints.Endpoint{Addr:addr});
    35  //	}
    36  //
    37  // Dial an RPC service using the etcd gRPC resolver and a gRPC Balancer:
    38  //
    39  //	func etcdDial(c *clientv3.Client, service string) (*grpc.ClientConn, error) {
    40  //		etcdResolver, err := resolver.NewBuilder(c);
    41  //		if err { return nil, err }
    42  //		return  grpc.Dial("etcd:///" + service, grpc.WithResolvers(etcdResolver))
    43  //	}
    44  //
    45  // Optionally, force delete an endpoint:
    46  //
    47  //	func etcdDelete(c *clientv3, service, addr string) error {
    48  //		em := endpoints.NewManager(c, service)
    49  //		return em.DeleteEndpoint(c.Ctx(), service+"/"+addr)
    50  //	}
    51  //
    52  // Or register an expiring endpoint with a lease:
    53  //
    54  //	func etcdAdd(c *clientv3.Client, lid clientv3.LeaseID, service, addr string) error {
    55  //		em := endpoints.NewManager(c, service)
    56  //		return em.AddEndpoint(c.Ctx(), service+"/"+addr, endpoints.Endpoint{Addr:addr}, clientv3.WithLease(lid));
    57  //	}
    58  package naming
    59  

View as plain text