soa

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 13 Imported by: 0

README

SOA

Usage:

s, err := soa.New(
    soa.WithApp(soa.AppConfig{
        ID:              "my-demo-svc",
        HealthCheckPath: "health",
    }),
    soa.WithConsul(soa.ConsulConfig{
        Host:  "127.0.0.1",
        Port:  8500,
        Token: "my-token",
    }),
)

if err != nil {
    log.Fatal("fail to create soa object")
}

// register service to consul
if err := s.Register(); err != nil {
    log.Fatal("fail to register service")
}

// resolve other service's address
host, err := s.Resolve("my-dependency-svc")

if err != nil {
    log.Println("fail to resolve my-dependency-svc")
}

fmt.Println(host.Addr)

// deregister service for graceful shutdown
s.Deregister()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	ID                  string
	Port                int
	HealthCheckPath     string
	HealthCheckTimeout  string
	HealthCheckInterval string
}

AppConfig is application config

type ConsulConfig

type ConsulConfig struct {
	Host  string
	Port  int
	Token string
}

ConsulConfig is consul config

type EmptyError

type EmptyError struct {
	// contains filtered or unexported fields
}

EmptyError is empty upstream pool error

func (*EmptyError) Error

func (ue *EmptyError) Error() string

Error returns error description

type Host

type Host struct {
	IP   string
	Port int
	Addr string
}

Host contains service ip and port

type Option

type Option func(*Options)

Option is for setting options

func WithApp

func WithApp(appCfg AppConfig) Option

WithApp sets application config

func WithConsul

func WithConsul(consulCfg ConsulConfig) Option

WithConsul sets consul config

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets logger

func WithUpstream

func WithUpstream(upstreamCfg UpstreamConfig) Option

WithUpstream sets upstream config

type Options

type Options struct {
	Logger   log.Logger
	App      AppConfig
	Consul   ConsulConfig
	Upstream UpstreamConfig
}

Options is soa options

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions creates options with defaults

type SOA

type SOA struct {
	Options      // inherited options
	ConsulClient *consulapi.Client
	Service      *consulapi.AgentServiceRegistration
	// contains filtered or unexported fields
}

SOA is for soa service registration and discovery

func New

func New(opts ...Option) (*SOA, error)

New creates a new SOA object

func (*SOA) Deregister

func (soa *SOA) Deregister() error

Deregister deregisters service

func (*SOA) Register

func (soa *SOA) Register() error

Register registers service

func (*SOA) Resolve

func (soa *SOA) Resolve(appID string) (*Host, error)

Resolve service address by app id

type UpstreamConfig

type UpstreamConfig struct {
	WaitTimeout time.Duration
	MaxRetries  int
}

UpstreamConfig is upstream config

Jump to

Keyboard shortcuts

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