api

package
v0.0.0-...-5695882 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 6 Imported by: 6

Documentation

Index

Constants

View Source
const ContentTypeApplicationJson = "application/json"
View Source
const ContentTypeHeader = "Content-Type"
View Source
const TenantDefault = "default"
View Source
const TenantKey = "tenant"

Variables

This section is empty.

Functions

func NewAlreadyRegisteredError

func NewAlreadyRegisteredError() error

func NewClientNotFoundError

func NewClientNotFoundError(clientId string) error

func NewMaxClientsReachedError

func NewMaxClientsReachedError(max int) error

func NewTenantNotFoundError

func NewTenantNotFoundError(tenant string) error

func NewTenantsClientNotFoundError

func NewTenantsClientNotFoundError(clientId string) error

Types

type Client

type Client interface {
	ClientId() string
	ServiceId() string
	Tenant() string
	Endpoints() []Endpoint
	Meta() map[string]any
	Ping() bool
	LastSeen() time.Time
	State() ClientState
	SetState(state ClientState)
	SetDirty(value bool)
	IsDirty() bool
}

type ClientState

type ClientState uint8
const (
	ClientStateUnknown ClientState = iota
	ClientStateStarting
	ClientStateUp
	ClientStateFailing
	ClientStateDown
	ClientStateRemoved
)

func (ClientState) MarshalJSON

func (ds ClientState) MarshalJSON() ([]byte, error)

func (ClientState) String

func (ds ClientState) String() string

func (*ClientState) UnmarshalJSON

func (ds *ClientState) UnmarshalJSON(data []byte) (err error)

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() (b []byte, err error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) (err error)

type Endpoint

type Endpoint interface {
	Url() string
	Type() EndpointType
}

func NewEndpoint

func NewEndpoint(url string) (Endpoint, error)

type EndpointType

type EndpointType uint8
const (
	UnknownEndpoint EndpointType = iota
	HttpEndpoint
	HttpsEndpoint
	GrpcEndpoint
)

type ErrAlreadyRegistered

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

func (*ErrAlreadyRegistered) Error

func (e *ErrAlreadyRegistered) Error() string

func (*ErrAlreadyRegistered) Is

func (e *ErrAlreadyRegistered) Is(tgt error) bool

type ErrClientNotFound

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

func (*ErrClientNotFound) Error

func (e *ErrClientNotFound) Error() string

func (*ErrClientNotFound) Is

func (e *ErrClientNotFound) Is(tgt error) bool

type ErrMaxClientsReached

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

func (*ErrMaxClientsReached) Error

func (e *ErrMaxClientsReached) Error() string

func (*ErrMaxClientsReached) Is

func (e *ErrMaxClientsReached) Is(tgt error) bool

type ErrTenantNotFound

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

func (*ErrTenantNotFound) Error

func (e *ErrTenantNotFound) Error() string

func (*ErrTenantNotFound) Is

func (e *ErrTenantNotFound) Is(tgt error) bool

type ErrTenantsClientNotFound

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

func (*ErrTenantsClientNotFound) Error

func (e *ErrTenantsClientNotFound) Error() string

func (*ErrTenantsClientNotFound) Is

func (e *ErrTenantsClientNotFound) Is(tgt error) bool

type JoinRequest

type JoinRequest struct {
	ServiceId string         `json:"service,omitempty"`
	Endpoints []string       `json:"endpoints,omitempty"`
	Meta      map[string]any `json:"meta,omitempty"`
}

type JoinResponse

type JoinResponse struct {
	ClientId     string   `json:"id,omitempty"`
	PingInterval Duration `json:"interval,omitempty"`
}

type Ping

type Ping struct {
}

type Pong

type Pong struct {
	Response PongType `json:"response"`
	Error    string   `json:"error"`
}

type PongType

type PongType uint8
const (
	PongTypeUnknown PongType = iota
	PongTypeOk
	PongTypeChanged
)

func (PongType) MarshalJSON

func (pt PongType) MarshalJSON() ([]byte, error)

func (PongType) String

func (pt PongType) String() string

func (*PongType) UnmarshalJSON

func (pt *PongType) UnmarshalJSON(data []byte) (err error)

type Registry

type Registry interface {
	Join(ctx context.Context, request JoinRequest) (*JoinResponse, error)
	Leave(ctx context.Context, clientId string) error
	List(ctx context.Context) []Client
	Ping(clientId string) (Pong, error)
}

type Tenant

type Tenant interface {
	Name() string
	Clients() []Client
	Get(clientId string) Client
	Set(clientId string, client Client)
	Delete(clientId string)
}

Jump to

Keyboard shortcuts

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