cloudmap

package module
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 13 Imported by: 0

README

AWS Cloud Map Resolver for grpc-go

Go Reference

grpc-cloudmap-resolver is an implementation of grpc-go.Resolver using AWS Cloud Map.

Installation

go get github.com/ab180/grpc-cloudmap-resolver

Example

See godoc for more details.

package main

import (
	"log"

	"google.golang.org/grpc"

	cloudmap "github.com/ab180/grpc-cloudmap-resolver"
)

func main() {
	// register custom builder
	// cloudmap.Register(
	// 	cloudmap.WithSession(your_session),
	// 	cloudmap.WithRefreshInterval(1 * time.Minute),
	// )

	conn, err := grpc.Dial(
		cloudmap.BuildTarget("your-namespace", "your-service"),
		grpc.WithInsecure(),
		grpc.WithBlock(),
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
	)
	if err != nil {
		log.Fatal("cannot create a grpc client connection")
	}

	_ = conn
}

Documentation

Index

Constants

View Source
const (
	Scheme = "cloudmap"

	HealthStatusFilterAll       = servicediscovery.HealthStatusFilterAll
	HealthStatusFilterHealthy   = servicediscovery.HealthStatusFilterHealthy
	HealthStatusFilterUnhealthy = servicediscovery.HealthStatusFilterUnhealthy
)

Variables

This section is empty.

Functions

func BuildTarget

func BuildTarget(namespace, service string) string

BuildTarget builds grpc target string with given namespace and service.

func Register

func Register(opts ...Opt)

Register builds builder with given opts and register it to the resolver map. If you don't give any options, the builder will be registered with default options listed below.

The default builder was already registered by the init function, so you don't need to call this function to register the default builder.

Default Options:

Session: session.NewSession()
HealthStatusFilter: HealthStatusFilterHealthy
MaxResults: 100
RefreshInterval: 30s

Types

type Opt

type Opt func(*builder)

func WithHealthStatusFilter

func WithHealthStatusFilter(healthStatusFilter string) Opt

func WithMaxResults

func WithMaxResults(maxResults int64) Opt

func WithRefreshInterval

func WithRefreshInterval(refreshInterval time.Duration) Opt

func WithSession

func WithSession(sess *session.Session) Opt

Jump to

Keyboard shortcuts

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