-
Notifications
You must be signed in to change notification settings - Fork 6
/
kuberesolver.go
33 lines (29 loc) · 1.13 KB
/
kuberesolver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package dgrpc
import (
"os"
"github.com/sercand/kuberesolver/v5"
"google.golang.org/grpc/resolver"
)
func init() {
if v := os.Getenv("GRPC_REGISTER_KUBERNETES_RESOLVER"); v != "false" {
RegisterKubernetesResolver("kubernetes")
}
}
// RegisterKubernetesResolver registers the "kubernetes" resolver with the given scheme. Refers
// to github.com/sercand/kuberesolver/v5 for more information about the `kubernetes:///` gRPC
// resolver.
//
// The `customScheme` is the scheme that will be used to register the resolver. It's usually
// `kubernetes` and should be performed close to the initialization of the application.
//
// func main() {
// dgrpc.RegisterKubernetesResolver("kubernetes")
// }
//
// **Important** The 'dgrpc' library already registers the kubernetes resolver with the 'kubernetes' scheme.
// so it's not necessary to call this function unless you want to use a different scheme. You can define
// the variable `GRPC_REGISTER_KUBERNETES_RESOLVER` to `false` to prevent the automatic registration.
// if needed.
func RegisterKubernetesResolver(customScheme string) {
resolver.Register(kuberesolver.NewBuilder(nil, customScheme))
}