Documentation ¶
Overview ¶
Package chrome exposes Go versions of Chrome's extension APIs.
Index ¶
- type BigStorage
- type C
- type PersistentStore
- type Storage
- type TypedStore
- func (t *TypedStore[V]) Delete(test func(v *V) bool, callback func(err error))
- func (t *TypedStore[V]) Read(test func(v *V) bool, callback func(value *V, err error))
- func (t *TypedStore[V]) ReadAll(callback func(values []*V, err error))
- func (t *TypedStore[V]) Write(value *V, callback func(err error))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BigStorage ¶ added in v0.0.20
type BigStorage struct {
// contains filtered or unexported fields
}
BigStorage supports storing and retrieving keys and values of arbitrary sizes in persistent storage. Items that fit within the per-item quota are stored normally; larger ones are split into multiple chunks.
Overall storage quota still applies, but this bypasses the per-item quotas.
BigStorage implements the PersistentStore interface.
func (*BigStorage) Delete ¶ added in v0.0.20
func (b *BigStorage) Delete(keys []string, callback func(err error))
See PersistentStore.Delete().
type C ¶
type C struct {
// contains filtered or unexported fields
}
C provides access to Chrome's extension APIs.
func New ¶
New returns an instance of C that can be used to access Chrome's extension APIs. Set chrome to nil to access the default Chrome API implementation; it should only be overridden for testing.
func (*C) Error ¶
Error returns the error (if any) from the last call. Returns nil if there was no error.
See https://developer.chrome.com/apps/runtime#property-lastError.
func (*C) OnConnectExternal ¶
OnConnectExternal installs a callback that will be invoked when an external connection is received.
See https://developer.chrome.com/apps/runtime#event-onConnectExternal.
func (*C) SendMessage ¶
SendMessage sends a message within our extension. While the underlying Chrome API supports sending a message to another extension, we only expose functionality to send within the same extension.
See https://developer.chrome.com/apps/runtime#method-sendMessage.
func (*C) SessionStorage ¶ added in v0.0.20
func (c *C) SessionStorage() PersistentStore
SessionStorage returns a PersistentStore object that can be used to to store data in memory. Data persists across Service Worker restarts.
See https://developer.chrome.com/apps/storage#property-session.
func (*C) SyncStorage ¶
func (c *C) SyncStorage() PersistentStore
SyncStorage returns a PersistentStore object that can be used to to store persistent data that is synchronized with Chrome Sync.
See https://developer.chrome.com/apps/storage#property-sync.
type PersistentStore ¶ added in v0.0.20
type PersistentStore interface { // Set stores new data. See chrome.Storage.Set() for details. Set(data map[string]js.Value, callback func(err error)) // Get gets data from storage. See chrome.Storage.Get() for details. Get(callback func(data map[string]js.Value, err error)) // Delete deletes data from storage. See chrome.Storage.Delete() for // details. Delete(keys []string, callback func(err error)) }
PersistentStore provides access to underlying storage. See chrome.Storage for details on the methods; using this interface allows for alternate implementations during testing.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage supports storing and retrieving data using Chrome's Storage API.
Storage implements the PersistentStore interface.
func (*Storage) Delete ¶
Delete removes the items from storage with the specified keys. If a key is not found in storage, it will be silently ignored (i.e., no error will be returned). Callback is invoked when complete.
See remove() in https://developer.chrome.com/apps/storage#type-StorageArea.
func (*Storage) Get ¶
Get reads all the data items currently stored. The callback will be invoked when complete, suppliing the items read and indicating any errors. The data suppiled with the callback is a map of key-value pairs, with each representing a distinct item from storage.
See get() in https://developer.chrome.com/apps/storage#type-StorageArea.
func (*Storage) Set ¶
Set stores new data in storage. data is a map of key-value pairs to be stored. If a key already exists, it will be overwritten. Callback will be invoked when complete.
See set() in https://developer.chrome.com/apps/storage#type-StorageArea.
type TypedStore ¶ added in v0.0.20
type TypedStore[V any] struct { // contains filtered or unexported fields }
TypedStore reads and writes typed values. They are serialized upon writing, and deserialized upon reading. If deserialization fails for a given value, it is ignored.
func NewTypedStore ¶ added in v0.0.20
func NewTypedStore[V any](store PersistentStore, keyPrefix string) *TypedStore[V]
NewTypedStore returns a new TypedStore using the underlying persistent store. keyPrefix is the prefix used to distinguish values from others in the same underlying store.
func (*TypedStore[V]) Delete ¶ added in v0.0.20
func (t *TypedStore[V]) Delete(test func(v *V) bool, callback func(err error))
Delete removes the value that matches the supplied test function. If multiple values match, all matching values are removed. callback is invoked upon completion.
func (*TypedStore[V]) Read ¶ added in v0.0.20
func (t *TypedStore[V]) Read(test func(v *V) bool, callback func(value *V, err error))
Read returns a single value that matches the supplied test function. If multiple values match, only the first is returned. callback is invoked with the returned value. If the value is not found, then the callback is invoked with a nil value.
func (*TypedStore[V]) ReadAll ¶ added in v0.0.20
func (t *TypedStore[V]) ReadAll(callback func(values []*V, err error))
ReadAll returns all the stored values. callback is invoked when complete.
func (*TypedStore[V]) Write ¶ added in v0.0.20
func (t *TypedStore[V]) Write(value *V, callback func(err error))
Write writes a new value to storage. callback is invoked when complete.