Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SharedMemoryContext ¶ added in v0.0.4
func SharedMemoryContext(ctx context.Context, shm *SharedMemory) context.Context
SharedMemoryContext stores shm on ctx for constructor injection.
Types ¶
type Record ¶
Record is a rich value type returned to PHP. Its exported fields are read from PHP via property access (`$rec->key`, `$rec->value`), matched case-insensitively.
type SharedMemory ¶ added in v0.0.4
type SharedMemory struct {
// contains filtered or unexported fields
}
SharedMemory is a host-owned in-memory key/value and counter store exposed to route PHP scripts. It behaves like request-shared SHM: each request gets a new VM, but all VMs can use the same Go value through `new SharedMemory`.
func NewSharedMemory ¶ added in v0.0.4
func NewSharedMemory() *SharedMemory
NewSharedMemory returns an empty shared-memory store.
func NewSharedMemoryBinding ¶ added in v0.0.4
func NewSharedMemoryBinding(ctx context.Context) (*SharedMemory, error)
NewSharedMemoryBinding returns the constructor registered for PHP `new SharedMemory`.
func (*SharedMemory) Count ¶ added in v0.0.4
func (m *SharedMemory) Count(_ context.Context, key string) string
Count returns a named counter as a string for simple PHP output checks.
func (*SharedMemory) Get ¶ added in v0.0.4
func (m *SharedMemory) Get(_ context.Context, key string) string
Get reads a string value. Missing keys return an empty string.
type Storage ¶
type Storage interface {
Set(ctx context.Context, key, value string)
Get(ctx context.Context, key string) (Record, error)
All(ctx context.Context) ([]Record, error)
Len() int64
Tenant() string
}
Storage is a host-provided key/value capability whose context parameters are supplied automatically when PHP invokes its methods.
Example ¶
ctx := context.WithValue(context.Background(), tenantKey, "acme")
storage, err := NewStorage(ctx)
if err != nil {
fmt.Println(err)
return
}
storage.Set(ctx, "color", "blue")
record, err := storage.Get(ctx, "color")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(storage.Tenant())
fmt.Println(record.Key, record.Value)
fmt.Println(storage.Len())
Output: acme color blue 1
func NewFailStorage ¶
NewFailStorage is a constructor that always fails, used to exercise the thrown-error path of `new`.