infra

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: LGPL-3.0 Imports: 31 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientConn

func NewClientConn[T ClientServiceNameGenerator](serviceName string, opts ...ClientOptions[T]) (*grpc.ClientConn, error)

func RegisterETCDRegisterPrefixKey

func RegisterETCDRegisterPrefixKey(prefix string)

RegisterETCDRegisterPrefixKey a function to change default register(etcd) prefix key

func RegisterEtcdClient

func RegisterEtcdClient(etcdConfig clientv3.Config) error

ResolveEtcdClient a function to register etcd client to watermelon global

func RegisterRegionProxy

func RegisterRegionProxy(region, proxy string)

RegisterRegionProxy set region's proxy endpoint

func ResolveEtcdClient

func ResolveEtcdClient() *clientv3.Client

ResolveEtcdClient a function to get registed etcd client

func ResolveProxy

func ResolveProxy(region string) string

ResolveProxy return region's proxy, if it exist

func SetShutdownDelaySeconds

func SetShutdownDelaySeconds(s int)

Types

type Address

type Address struct {
	ListenAddress string // exp: 10.0.0.1 or 10.0.0.1:12345 or :12345 (used host-ip:12345)
	// register-address will be equal listen-address when it is empty
	//
	// The registration address does not need to provide a port number.
	// Even if it is provided, it will be replaced with the port number
	// used by the listening address, unless a valid URL address is provided.
	// If the provided URL address needs to automatically fill in the port
	// number information used by the listener, you can use `{port}“ as a
	// template for the port number filling.
	RegisterAddress string
	// contains filtered or unexported fields
}

type COptions

type COptions[T ClientServiceNameGenerator] struct {
	CustomizeMeta T
	// contains filtered or unexported fields
}

type Client

type Client[T ClientServiceNameGenerator] struct {
	CustomizeMeta T
}

type ClientOptions

type ClientOptions[T ClientServiceNameGenerator] func(c *COptions[T])

func WithGrpcDialOptions

func WithGrpcDialOptions[T ClientServiceNameGenerator](opts ...grpc.DialOption) ClientOptions[T]

type ClientServiceNameGenerator

type ClientServiceNameGenerator interface {
	FullServiceName(srvName string) string
	ProxyMetadata() metadata.MD
}

type Option

type Option[T interface {
	WithMeta(register.NodeMeta) T
}] func(s *SrvInfo[T])

func WithAddress

func WithAddress[T interface {
	WithMeta(register.NodeMeta) T
}](addrs []Address) Option[T]

func WithGrpcServerOptions

func WithGrpcServerOptions[T interface {
	WithMeta(register.NodeMeta) T
}](opts ...grpc.ServerOption) Option[T]

func WithHttpServer

func WithHttpServer[T interface {
	WithMeta(register.NodeMeta) T
}](srv *http.Server) Option[T]

func WithServiceRegister

func WithServiceRegister[T interface {
	WithMeta(register.NodeMeta) T
}](r register.ServiceRegister[T]) Option[T]

type ServerConfig

type ServerConfig struct {
	Namespace string
	ListenOn  string
}

type Srv

type Srv[T interface {
	WithMeta(register.NodeMeta) T
}] struct {
	*SrvInfo[T]

	middleware.RouterGroup
	// contains filtered or unexported fields
}

func NewServer

func NewServer[T interface {
	WithMeta(register.NodeMeta) T
}](register func(srv *grpc.Server), opts ...Option[T]) *Srv[T]

func (*Srv[T]) Addrs

func (s *Srv[T]) Addrs() []*net.TCPAddr

Addrs It will always return nil before the service is started

func (*Srv[T]) Register added in v0.1.3

func (s *Srv[T]) Register() error

func (*Srv[T]) RunUntil

func (s *Srv[T]) RunUntil(signals ...os.Signal)

RunUntil start server and shutdown until receive signals

func (*Srv[T]) ShutDown

func (s *Srv[T]) ShutDown()

type SrvInfo

type SrvInfo[T interface {
	WithMeta(register.NodeMeta) T
}] struct {
	CustomInfo T
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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