github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/exttinygo/README.md (about)

     1  # exttinygo
     2  
     3  ## Principles
     4  
     5  - Exchange buffer: 1MB of memory is pre-allocated for each instance of the extension
     6  - gc=leaking
     7  
     8  ## Usage
     9  
    10  ```go
    11  package main
    12  
    13  import (
    14  	ext "github.com/voedger/voedger/pkg/exttinygo"
    15  )
    16  
    17  //export exampleExtension
    18  func exampleExtension() {
    19  	event := ext.GetValue(ext.KeyBuilder(ext.StorageEvent, ext.NullEntity))
    20  
    21  	if event.AsString("qname") == "air.UpdateSubscription" {
    22  		json := event.AsValue("arg")
    23  		subscr := json.AsValue("subscription")
    24  		customer := json.AsValue("customer")
    25  		mail := ext.NewValue(ext.KeyBuilder(ext.StorageSendmail, ext.NullEntity))
    26  		mail.PutString("from", "test@gmail.com")
    27  		mail.PutString("to", customer.AsString("email"))
    28  		mail.PutString("body", "Your subscription has been updated. New status: "+subscr.AsString("status"))
    29  	}
    30  }
    31  ```