infrastructure

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Deprecated: will be moved into another package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServiceExists occurs when you trying to register a service that already exists
	ErrServiceExists = errors.New("service exists")
)
View Source
var ErrServiceNotExists = errors.New("service is not exists")

ErrServiceNotExists occurs when you trying to add a server to service that not exists

View Source
var (
	// ErrServiceTypeNotFound occurs when unknown service type
	// passed in GetTypeByString
	ErrServiceTypeNotFound = errors.New("service type not found")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	Host string `json:"host"`
	Port int    `json:"port"`
	URL  string `json:"url"`
}

Address defines service addr

type Infrastructure

type Infrastructure struct {
	Services         map[string]*Service `json:"services"`
	UpdateTimestamp  int64               `json:"update_timestamp"`
	CurrentTimestamp int64               `json:"current_timestamp"`
	Lock             *sync.RWMutex       `json:"-"`
}

Infrastructure handles lists of services and current timestamp

func New

func New() *Infrastructure

New initializes an empty infrastructure

func (*Infrastructure) AddServiceServer

func (i *Infrastructure) AddServiceServer(serviceName string, addr Address) error

AddServiceServer registers server to a service in the infrastructure

func (*Infrastructure) MergeService

func (i *Infrastructure) MergeService(name string, s Service)

MergeService in the infrastructure

func (*Infrastructure) RegisterService

func (i *Infrastructure) RegisterService(name string, s Service) error

RegisterService in the infrastructure

func (*Infrastructure) RegisterServiceBatch

func (i *Infrastructure) RegisterServiceBatch(m map[string]Service) error

RegisterServiceBatch registers services from given map[service name]Service Returns error if service already exists

func (*Infrastructure) RegisterServiceBatchIgnore

func (i *Infrastructure) RegisterServiceBatchIgnore(m map[string]Service)

RegisterServiceBatchIgnore registers services from given map[service name]Service Ignores any error if service already exists

type Service

type Service struct {
	Name      string      `json:"name"`
	Addresses []Address   `json:"addresses"`
	Type      ServiceType `json:"type"`
}

Service defines an abstract service in infrastructure

type ServiceType

type ServiceType string

ServiceType defines a type of protocol that service using

const (
	// HTTP service type
	HTTP ServiceType = "http"
	// HTTPS service type
	HTTPS ServiceType = "https"
	// TCP service type
	TCP ServiceType = "tcp"
	// UDP service type
	UDP ServiceType = "udp"
	// Custom protocol service type
	Custom ServiceType = "custom"
)

func GetTypeByString

func GetTypeByString(typeName string) (ServiceType, error)

GetTypeByString returns a ServiceType associated with given typeName and nil, if type is known, otherwise instantiates a ServiceType with given typeName but returns ErrServiceTypeNotFound

Jump to

Keyboard shortcuts

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