services

package
v1.2.85 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: Apache-2.0 Imports: 31 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDeviceId               = errors.NotAcceptable("fns: X-Fns-Device-Id is required")
	ErrInvalidPath            = errors.Warning("fns: invalid path")
	ErrInvalidBody            = errors.Warning("fns: invalid body")
	ErrInvalidRequestVersions = errors.Warning("fns: invalid request versions")
)
View Source
var (
	EmptyBytes []byte
)

Functions

func Handler

func Handler(endpoints Endpoints) transports.MuxHandler

func HashRequest

func HashRequest(r Request, options ...HashRequestOption) (p []byte, err error)

func LoadComponent

func LoadComponent[C Component](ctx context.Context, service []byte, name string) (c C, has bool)

func MarkDeprecated added in v1.2.60

func MarkDeprecated(ctx context.Context)

func ReleaseRequest

func ReleaseRequest(r Request)

func TryLoadRequestHash added in v1.2.0

func TryLoadRequestHash(ctx context.Context) (p []byte, has bool)

func ValueOfParam added in v1.2.0

func ValueOfParam[T any](param Param) (v T, err error)

ValueOfParam type of T must be struct value or slice, can not be ptr

func ValueOfResponse added in v1.2.0

func ValueOfResponse[T any](response Response) (v T, err error)

ValueOfResponse type of T must be struct value or slice, can not be ptr

func WithComponents

func WithComponents(ctx context.Context, service []byte, components Components)

Types

type Abstract

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

func NewAbstract

func NewAbstract(name string, internal bool, components ...Component) Abstract

func (*Abstract) AddFunction

func (abstract *Abstract) AddFunction(fn Fn)

func (*Abstract) Components

func (abstract *Abstract) Components() (components Components)

func (*Abstract) Construct

func (abstract *Abstract) Construct(options Options) (err error)

func (*Abstract) Document

func (abstract *Abstract) Document() (document documents.Endpoint)

func (*Abstract) Functions

func (abstract *Abstract) Functions() (functions Fns)

func (*Abstract) Id

func (abstract *Abstract) Id() string

func (*Abstract) Internal

func (abstract *Abstract) Internal() (internal bool)

func (*Abstract) Log

func (abstract *Abstract) Log() (log logs.Logger)

func (*Abstract) Name

func (abstract *Abstract) Name() (name string)

func (*Abstract) Shutdown

func (abstract *Abstract) Shutdown(ctx context.Context)

func (*Abstract) Version

func (abstract *Abstract) Version() versions.Version

type Component

type Component interface {
	Name() (name string)
	Construct(options Options) (err error)
	Shutdown(ctx context.Context)
}

type Components

type Components []Component

func LoadComponents

func LoadComponents(ctx context.Context, service []byte) Components

func (Components) Get

func (components Components) Get(name string) (v Component, has bool)

type Config

type Config map[string]json.RawMessage

func (Config) Get

func (config Config) Get(name string) (v configures.Config, err error)

type Empty

type Empty struct{}

Empty @name Empty @description Empty object

func (Empty) MarshalJSON added in v1.2.0

func (e Empty) MarshalJSON() ([]byte, error)

type Endpoint

type Endpoint interface {
	Name() (name string)
	Internal() (ok bool)
	Document() (document documents.Endpoint)
	Functions() (functions Fns)
	Shutdown(ctx context.Context)
}

type EndpointGetOption

type EndpointGetOption func(options *EndpointGetOptions)

func EndpointId

func EndpointId(id []byte) EndpointGetOption

func EndpointVersions

func EndpointVersions(requestVersions versions.Intervals) EndpointGetOption

type EndpointGetOptions

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

func (EndpointGetOptions) Id

func (options EndpointGetOptions) Id() []byte

func (EndpointGetOptions) Versions

func (options EndpointGetOptions) Versions() versions.Intervals

type EndpointInfo

type EndpointInfo struct {
	Id        string             `json:"id"`
	Version   versions.Version   `json:"version"`
	Address   string             `json:"address"`
	Name      string             `json:"name"`
	Internal  bool               `json:"internal"`
	Functions FnInfos            `json:"functions"`
	Document  documents.Endpoint `json:"document"`
}

type EndpointInfos

type EndpointInfos []EndpointInfo

func (EndpointInfos) Find

func (infos EndpointInfos) Find(name []byte) (info EndpointInfo, found bool)

func (EndpointInfos) Len

func (infos EndpointInfos) Len() int

func (EndpointInfos) Less

func (infos EndpointInfos) Less(i, j int) bool

func (EndpointInfos) Swap

func (infos EndpointInfos) Swap(i, j int)

type Endpoints

type Endpoints interface {
	Info() (infos EndpointInfos)
	Get(ctx context.Context, name []byte, options ...EndpointGetOption) (endpoint Endpoint, has bool)
	RequestAsync(ctx context.Context, name []byte, fn []byte, param any, options ...RequestOption) (future futures.Future, err error)
	Request(ctx context.Context, name []byte, fn []byte, param any, options ...RequestOption) (response Response, err error)
}

type EndpointsManager

type EndpointsManager interface {
	Endpoints
	Add(service Service) (err error)
	Listen(ctx context.Context) (err error)
	Shutdown(ctx context.Context)
}

func New

func New(id string, version versions.Version, log logs.Logger, config Config, worker workers.Workers) EndpointsManager

type Fn

type Fn interface {
	Name() string
	Internal() bool
	Readonly() bool
	Handle(ctx Request) (v any, err error)
}

type FnInfo

type FnInfo struct {
	Name     string `json:"name"`
	Readonly bool   `json:"readonly"`
	Internal bool   `json:"internal"`
}

type FnInfos

type FnInfos []FnInfo

func (FnInfos) Find

func (f FnInfos) Find(name []byte) (info FnInfo, found bool)

func (FnInfos) Len

func (f FnInfos) Len() int

func (FnInfos) Less

func (f FnInfos) Less(i, j int) bool

func (FnInfos) Swap

func (f FnInfos) Swap(i, j int)

type FnTask

type FnTask struct {
	Fn      Fn
	Promise futures.Promise
}

func (FnTask) Execute

func (task FnTask) Execute(ctx sc.Context)

type Fns

type Fns []Fn

func (Fns) Add

func (f Fns) Add(v Fn) Fns

func (Fns) Find

func (f Fns) Find(name []byte) (v Fn, found bool)

func (Fns) Len

func (f Fns) Len() int

func (Fns) Less

func (f Fns) Less(i, j int) bool

func (Fns) Swap

func (f Fns) Swap(i, j int)

type HashRequestOption

type HashRequestOption func(options *HashRequestOptions)

func HashRequestBySumFn

func HashRequestBySumFn(fn func(p []byte) uint64) HashRequestOption

func HashRequestWithDeviceId

func HashRequestWithDeviceId() HashRequestOption

func HashRequestWithToken

func HashRequestWithToken() HashRequestOption

type HashRequestOptions

type HashRequestOptions struct {
	// contains filtered or unexported fields
}
type Header struct {
	// contains filtered or unexported fields
}

func (Header) AcceptedVersions

func (header Header) AcceptedVersions() versions.Intervals

func (Header) DeviceId

func (header Header) DeviceId() []byte

func (Header) DeviceIp

func (header Header) DeviceIp() []byte

func (Header) EndpointId

func (header Header) EndpointId() []byte

func (Header) Internal

func (header Header) Internal() bool

func (Header) ProcessId

func (header Header) ProcessId() []byte

func (Header) RequestId

func (header Header) RequestId() []byte

func (Header) Token

func (header Header) Token() []byte

type Listenable

type Listenable interface {
	Service
	// Listen
	// ctx with runtime
	Listen(ctx context.Context) (err error)
}

type Manager

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

func (*Manager) Add

func (manager *Manager) Add(service Service) (err error)

func (*Manager) Get

func (manager *Manager) Get(_ context.Context, name []byte, options ...EndpointGetOption) (endpoint Endpoint, has bool)

func (*Manager) Info

func (manager *Manager) Info() (infos EndpointInfos)

func (*Manager) Listen

func (manager *Manager) Listen(ctx context.Context) (err error)

func (*Manager) Request

func (manager *Manager) Request(ctx context.Context, name []byte, fn []byte, param interface{}, options ...RequestOption) (response Response, err error)

func (*Manager) RequestAsync added in v1.2.34

func (manager *Manager) RequestAsync(ctx context.Context, name []byte, fn []byte, param any, options ...RequestOption) (future futures.Future, err error)

func (*Manager) Shutdown

func (manager *Manager) Shutdown(ctx context.Context)

type Middleware added in v1.1.3

type Middleware interface {
	transports.Middleware
	Services() []Service
}

type MuxHandler added in v1.1.3

type MuxHandler interface {
	transports.MuxHandler
	Services() []Service
}

type Options

type Options struct {
	Id      string
	Version versions.Version
	Log     logs.Logger
	Config  configures.Config
}

type Param

type Param interface {
	objects.Object
}

func NewParam

func NewParam(src interface{}) Param

type Request

type Request interface {
	context.Context
	Fn() (endpoint []byte, fn []byte)
	Header() (header Header)
	Param() (param Param)
}

func AcquireRequest

func AcquireRequest(ctx context.Context, service []byte, fn []byte, param interface{}, options ...RequestOption) (v Request)

func LoadRequest

func LoadRequest(ctx context.Context) Request

func NewRequest added in v1.2.34

func NewRequest(ctx context.Context, service []byte, fn []byte, param interface{}, options ...RequestOption) (v Request)

func TryLoadRequest

func TryLoadRequest(ctx context.Context) (r Request, ok bool)

type RequestOption

type RequestOption func(*RequestOptions)

func WithDeviceId

func WithDeviceId(id []byte) RequestOption

func WithDeviceIp

func WithDeviceIp(ip []byte) RequestOption

func WithEndpointId

func WithEndpointId(id []byte) RequestOption

func WithInternalRequest

func WithInternalRequest() RequestOption

func WithProcessId

func WithProcessId(id []byte) RequestOption

func WithRequestId

func WithRequestId(id []byte) RequestOption

func WithRequestVersions

func WithRequestVersions(acceptedVersions versions.Intervals) RequestOption

func WithToken

func WithToken(token []byte) RequestOption

type RequestOptions

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

type Response

type Response interface {
	objects.Object
}

func NewResponse

func NewResponse(src any) Response

type Service

type Service interface {
	Endpoint
	Construct(options Options) (err error)
	Components() (components Components)
}

type Services

type Services []Service

func (Services) Add

func (s Services) Add(v Service) Services

func (Services) Find

func (s Services) Find(name []byte) (v Service, found bool)

func (Services) Len

func (s Services) Len() int

func (Services) Less

func (s Services) Less(i, j int) bool

func (Services) Swap

func (s Services) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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