view

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 4 Imported by: 48

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 {
	SpanStarter

	// 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.
	// Sessions are scoped by the caller view and cached.
	// The session can be bound to other caller views by passing them as additional parameters.
	GetSession(caller View, party Identity, boundToViews ...View) (Session, error)

	// GetSessionByID returns a session to the passed remote party and id.
	// Cashing may be used.
	GetSessionByID(id string, party Identity) (Session, 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 = identity.Identity

Identity wraps the byte representation of a lower level 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
	Ctx          context.Context
}

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

	// SendWithContext sends the payload to the endpoint with the passed context
	SendWithContext(ctx context.Context, payload []byte) error

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

	// SendErrorWithContext sends an error to the endpoint with the passed payload and context
	SendErrorWithContext(ctx context.Context, 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 SpanStarter added in v0.4.0

type SpanStarter interface {
	// StartSpanFrom creates a new child span from the passed context
	StartSpanFrom(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
}

SpanStarter creates new spans

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