view

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 5 Imported by: 55

Documentation

Index

Constants

View Source
const (
	OK    = 200
	ERROR = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// GetService returns an instance of the given type
	GetService(v interface{}) (interface{}, error)

	// ID returns the identifier of this context
	ID() string

	// RunView runs the passed view on input this context
	RunView(view View, opts ...RunViewOption) (interface{}, error)

	// Me returns the identity bound to this context
	Me() Identity

	// IsMe returns true if the passed identity is an alias
	// of the identity bound to this context, false otherwise
	IsMe(id Identity) bool

	// Initiator returns the View that initiate a call
	Initiator() View

	// GetSession returns a session to the passed remote
	// party for the given view caller.
	// Cashing may be be used.
	GetSession(caller View, party Identity) (Session, error)

	// GetSessionByID returns a session to the passed remote party and id.
	// Cashing may be used.
	GetSessionByID(id string, party Identity) (Session, error)

	ResetSessions() error

	// Session returns the session created to respond to a
	// remote party, nil if the context was created
	// not to respond to a remote call
	Session() Session

	// Context return the associated context.Context
	Context() context.Context

	// OnError appends to passed callback function to the list of functions called when
	// the current execution return an error or panic.
	// This is useful to release resources.
	OnError(callback func())
}

Context gives a view information about the environment in which it is in execution

type Identity

type Identity []byte

Identity wraps the byte representation of a lower level identity.

func (Identity) Bytes

func (id Identity) Bytes() []byte

Bytes returns the byte representation of this identity

func (Identity) Equal

func (id Identity) Equal(id2 Identity) bool

Equal return true if the identities are the same

func (Identity) Hash

func (id Identity) Hash() string

Hash returns the hash of this identity

func (Identity) IsNone

func (id Identity) IsNone() bool

IsNone returns true if this identity is empty

func (Identity) String

func (id Identity) String() string

String returns a string representation of this identity

func (Identity) UniqueID

func (id Identity) UniqueID() string

UniqueID returns a unique identifier of this identity

type Message

type Message struct {
	SessionID    string // Session Identifier
	ContextID    string // Context Identifier
	Caller       string // View Identifier of the caller
	FromEndpoint string // Endpoint identifier of the caller
	FromPKID     []byte // PK identifier of the caller
	Status       int32  // Message Status (OK, ERROR)
	Payload      []byte // Payload
}

func (*Message) String

func (m *Message) String() string

type MutableContext

type MutableContext interface {
	// ResetSessions disposes all sessions created in this context
	ResetSessions() error
	// PutService registers a service in this context
	PutService(v interface{}) error
}

MutableContext models a mutable context

type RunViewOption

type RunViewOption func(*RunViewOptions) error

RunViewOption models a function that set options to run a view

func AsInitiator

func AsInitiator() RunViewOption

AsInitiator tells the context to initialize the initiator to the executing view

func AsResponder

func AsResponder(session Session) RunViewOption

AsResponder sets the context's session to the passed session

func WithSameContext

func WithSameContext() RunViewOption

WithSameContext is used to reuse the context

func WithViewCall

func WithViewCall(f func(Context) (interface{}, error)) RunViewOption

WithViewCall sets the Call function to invoke. When specified, it overrides all options and arguments passing a view

type RunViewOptions

type RunViewOptions struct {
	Session     Session
	AsInitiator bool
	Call        func(Context) (interface{}, error)
	SameContext bool
}

RunViewOptions models the options to run a view

func CompileRunViewOptions

func CompileRunViewOptions(opts ...RunViewOption) (*RunViewOptions, error)

CompileRunViewOptions compiles a set of RunViewOption to a RunViewOptions

type Session

type Session interface {
	Info() SessionInfo

	// Send sends the payload to the endpoint
	Send(payload []byte) error

	// SendError sends an error to the endpoint with the passed payload
	SendError(payload []byte) error

	// Receive returns a channel of messages received from the endpoint
	Receive() <-chan *Message

	// Close releases all the resources allocated by this session
	Close()
}

Session encapsulates a communication channel to an endpoint

type SessionInfo

type SessionInfo struct {
	ID           string
	Caller       Identity
	CallerViewID string
	Endpoint     string
	EndpointPKID []byte
	Closed       bool
}

func (*SessionInfo) String

func (i *SessionInfo) String() string

type View

type View interface {
	// Call invokes the View on input the passed argument.
	// It returns a result and error in case of failure.
	Call(context Context) (interface{}, error)
}

View wraps a callable function.

Jump to

Keyboard shortcuts

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