Documentation ¶
Overview ¶
Package golang includes The runtime, which is just a stub that connects the cocoon code to the connector's RPC server. The runtime provides access to APIs for various operations.
Index ¶
- Variables
- func GetCocoonID() string
- func GetID() string
- func GetLogger() *logging.Logger
- func GetSystemCocoonID() string
- func GetSystemPublicLedgerName() string
- func HasView(name string) bool
- func Render(name string, dataSource interface{}) ([]byte, error)
- func RenderString(eml string, dataSource interface{}) (content []byte, err error)
- func Run(cc CocoonCode)
- func SetDebugLevel(level logging.Level)
- func Stop(exitCode int)
- type CocoonCode
- type Link
- func (link *Link) Get(ledgerName, key string) (*types.Transaction, error)
- func (link *Link) GetBlock(ledgerName, id string) (*types.Block, error)
- func (link *Link) GetCocoonID() string
- func (link *Link) GetIncomingMeta() Metadata
- func (link *Link) GetInvokeID() string
- func (link *Link) GetLedger(ledgerName string) (*types.Ledger, error)
- func (link *Link) IsNative() bool
- func (link *Link) Lock(key string, ttl time.Duration) (*Lock, error)
- func (link *Link) NewLedger(name string, chained, public bool) (*types.Ledger, error)
- func (link *Link) NewRangeGetter(ledgerName, start, end string, inclusive bool) *RangeGetter
- func (link *Link) Put(ledgerName, key string, value []byte) (*types.Transaction, error)
- func (link *Link) PutSafe(revisionID, ledgerName, key string, value []byte) (*types.Transaction, error)
- type Lock
- type Metadata
- type RangeGetter
- type View
Constants ¶
This section is empty.
Variables ¶
var ( // System link System = NewLink(types.SystemCocoonID) // Native link refers to a link that points // to the resources of a natively linked cocoon. If the current cocoon // has not native link to another cocoon, then the link points to its own resource Native = newNativeLink(GetID()) // Me link refers to a link that points the resources of the current cocoon respective // of whether the cocoon is natively linked to another cocoon. Me = NewLink(GetCocoonID()) // SourceDir is the root directory of the running cocoon code SourceDir = os.Getenv("SOURCE_DIR") // ViewDir is the directory where view files are stored ViewDir = path.Join(SourceDir, "/static/views") )
var ErrLockNotAcquired = fmt.Errorf("lock not acquired")
ErrLockNotAcquired defines an error about a lock not acquired
var ( // ErrNoTransaction represents a lack of transaction ErrNoTransaction = fmt.Errorf("no transaction") )
var ErrObjectLocked = fmt.Errorf("failed to acquire lock. object has been locked by another process")
ErrObjectLocked reprents an error about an object or transaction locked by another process
var ( // ErrViewNotFound indicates an unknown view file ErrViewNotFound = fmt.Errorf("view file not found") )
Functions ¶
func GetID ¶
func GetID() string
GetID returns the cocoon id. However, it will return the natively linked cocoon id if this cocoon is linked to another cocoon.
func GetSystemCocoonID ¶
func GetSystemCocoonID() string
GetSystemCocoonID returns the system cocoon id
func GetSystemPublicLedgerName ¶
func GetSystemPublicLedgerName() string
GetSystemPublicLedgerName returns the name of the system ledger.
func Render ¶
Render creates a View from am eml view file and a data source. Data source can be a map or a struct type. The created View is json encoded.
func RenderString ¶
RenderString creates a view from an eml component and a data source. Data source can be a map or a struct type.The created View is json encoded.
func Run ¶
func Run(cc CocoonCode)
Run starts the stub server, takes a cocoon code and attempts to initialize it..
func SetDebugLevel ¶
func SetDebugLevel(level logging.Level)
SetDebugLevel sets the default logger debug level
Types ¶
type CocoonCode ¶
type CocoonCode interface { OnInit() error OnInvoke(header Metadata, function string, params []string) ([]byte, error) OnStop() }
CocoonCode defines the interface of a cocoon code.
type Link ¶
type Link struct { InMetadata Metadata // incoming metadata // contains filtered or unexported fields }
Link provides access to all platform services available to the cocoon code.
func (*Link) Get ¶
func (link *Link) Get(ledgerName, key string) (*types.Transaction, error)
Get gets a transaction from a ledger
func (*Link) GetCocoonID ¶
GetCocoonID returns the cocoon id attached to this link
func (*Link) GetIncomingMeta ¶
GetIncomingMeta returns the metadata included in the link.
func (*Link) GetInvokeID ¶
GetInvokeID returns the transaction id of the invoke request. Returns an empty string if link was not created as a result of an invoke request
func (*Link) Lock ¶
Lock acquires a lock on the specified key within the scope of the linked cocoon code. An error is returned if it failed to acquire the lock.
func (*Link) NewLedger ¶
NewLedger creates a new ledger by sending an invoke transaction (TxNewLedger) to the connector. If chained is set to true, a blockchain is created and subsequent PUT operations to the ledger will be included in the types. Otherwise, PUT operations will only be included in the types.
func (*Link) NewRangeGetter ¶
func (link *Link) NewRangeGetter(ledgerName, start, end string, inclusive bool) *RangeGetter
NewRangeGetter creates an instance of a RangeGetter for a specified ledger.
func (*Link) PutSafe ¶
func (link *Link) PutSafe(revisionID, ledgerName, key string, value []byte) (*types.Transaction, error)
PutSafe puts a transaction and also ensures that no previous transaction references the revision id provided. If a previous transaction references the revision id, an ErrStateObject is returned. This is useful for situations where CAS (check-an-set) procedure is a requirement. Use the ID of previous transactions to ensure updates are not made based on records that may have been updated by another process.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock defines a structure for a platform-wide lock mechanism
func (*Lock) Acquire ¶
Acquire will attempt to acquire a lock on the key within the cocoon scope defined in the lock instance. If successful, Lock object is returned. An acquired lock will also be enforced in other linked cocoon codes.
func (*Lock) IsAcquirer ¶
IsAcquirer checks whether lock session is still active. If the lock is still active, nil is returned.
type Metadata ¶
Metadata defines a structure for storing link related header information
type RangeGetter ¶
type RangeGetter struct { Error error // contains filtered or unexported fields }
RangeGetter defines a means to fetch keys of a specific range with support for
func NewRangeGetter ¶
func NewRangeGetter(ledgerName, to, start, end string, inclusive bool) *RangeGetter
NewRangeGetter creates a new range getter to traverse a specific ledger. Set start and end key will get transactions between those keys. However, the end key is not included by default. Set inclusive to true to include the end key. Set only start to get all keys matching that key as a prefix or set only end key to get match keys as a surfix.
func (*RangeGetter) HasNext ¶
func (rg *RangeGetter) HasNext() bool
HasNext determines whether more rows exists.
func (*RangeGetter) Next ¶
func (rg *RangeGetter) Next() *types.Transaction
Next returns a transaction if available or nil
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package proto_runtime is a generated protocol buffer package.
|
Package proto_runtime is a generated protocol buffer package. |