in go/showcase/pkg/showcase/part4/storage.go [62:94]
func (s StateStorageFn) Invoke(ctx statefun.Context, msg statefun.Message) error {
// each function invocation gets access to storage that is scoped to the current function
// instance's address, i.e. (function typename, instance id). For example, if (UserFn, "Gordon")
// was invoked, the values you get access to belongs specifically to user Gordon.
storage := ctx.Storage()
// you can think of the storage having several "columns", with each column identified by an
// uniquely named ValueSpec. Using the ValueSpec instances, you can access the value of
// individual columns. Get returns a boolean indicating whether there is an existing
// value, so you can differentiate between missing and the zero value.
var storedInt int32
_ = storage.Get(s.IntValue, &storedInt)
var boolValue bool
exists := storage.Get(s.BoolValue, &boolValue)
var login part1.UserLogin
_ = storage.Get(s.UserLoginValue, &login)
// the ValueSpec instance is also used for manipulating the stored values, e.g. updating ...
storage.Set(s.IntValue, storedInt+1)
if !exists {
boolValue = true
}
storage.Set(s.BoolValue, boolValue)
// ... or clearing the value!
storage.Remove(s.UserLoginValue)
return nil
}