package services

import "github.com/nats-io/nats.go/services"

Index

Constants

const (
	// We can fix this, as versions will be on separate subjects and use account mapping to roll requests to new versions etc.
	QG = "svc"

	// ServiceApiPrefix is the root of all control subjects
	ServiceApiPrefix = "$SRV"

	ServiceErrorHeader = "Nats-Service-Error"
)

Functions

func SvcControlSubject

func SvcControlSubject(verb ServiceVerb, kind, id string) (string, error)

SvcControlSubject returns monitoring subjects used by the ServiceImpl

Types

type Endpoint

type Endpoint struct {
	Subject string `json:"subject"`
	Handler ServiceHandler
}

func (*Endpoint) Valid

func (e *Endpoint) Valid() error

type InternalEndpoint

type InternalEndpoint struct {
	Name    string
	Handler nats.MsgHandler
}

type Service

type Service interface {
	ID() string
	Name() string
	Description() string
	Version() string
	Stats() ServiceStats
	Reset()
	Stop()
}

Service is an interface for service management. It exposes methods to stop/reset a service, as well as get information on a service.

func Add

func Add(nc *nats.Conn, config ServiceConfig) (Service, error)

Add adds a microservice. NOTE we can do an OpenAPI version as well, but looking at it it was very involved. So I think keep simple version and also have a version that talkes full blown OpenAPI spec and we can pull these things out.

type ServiceAPIError

type ServiceAPIError struct {
	ErrorCode   int
	Description string
}

func (*ServiceAPIError) Error

func (e *ServiceAPIError) Error() string

type ServiceConfig

type ServiceConfig struct {
	Name          string        `json:"name"`
	Description   string        `json:"description"`
	Version       string        `json:"version"`
	Schema        ServiceSchema `json:"schema"`
	Endpoint      Endpoint      `json:"endpoint"`
	StatusHandler func(Endpoint) interface{}
}

func (*ServiceConfig) Valid

func (s *ServiceConfig) Valid() error

type ServiceHandler

type ServiceHandler func(svc Service, req *nats.Msg) error

A request handler. TODO (could make error more and return more info to user automatically?)

type ServiceInfo

type ServiceInfo struct {
	Name        string `json:"name"`
	ID          string `json:"id"`
	Description string `json:"description"`
	Version     string `json:"version"`
	Subject     string `json:"subject"`
}

ServiceInfo is the basic information about a service type

type ServiceSchema

type ServiceSchema struct {
	Request  string `json:"request"`
	Response string `json:"response"`
}

type ServiceStats

type ServiceStats struct {
	Name      string    `json:"name"`
	ID        string    `json:"id"`
	Version   string    `json:"version"`
	Started   time.Time `json:"started"`
	Endpoints []Stats   `json:"stats"`
}

Clients can request as well.

type ServiceVerb

type ServiceVerb int64
const (
	SrvPing ServiceVerb = iota
	SrvStatus
	SrvInfo
	SrvSchema
)

func (ServiceVerb) String

func (s ServiceVerb) String() string

type Stats

type Stats struct {
	Name           string        `json:"name"`
	NumRequests    int           `json:"num_requests"`
	NumErrors      int           `json:"num_errors"`
	TotalLatency   time.Duration `json:"total_latency"`
	AverageLatency time.Duration `json:"average_latency"`
	Data           interface{}   `json:"data"`
}

Source Files

errors.go service.go

Version
v1.21.0
Published
Dec 5, 2022
Platform
js/wasm
Imports
8 packages
Last checked
55 minutes ago

Tools for package owners.