<!-- Code generated by gomarkdoc. DO NOT EDIT -->

```go
import "github.com/Azure/iot-operations-sdks/go/services/statestore"
```

## Index

- [Variables](<#variables>)
- [type ArgumentError](<#ArgumentError>)
- [type Bytes](<#Bytes>)
- [type Client](<#Client>)
  - [func New\[K, V Bytes\]\(app \*protocol.Application, client MqttClient, opt ...ClientOption\) \(c \*Client\[K, V\], err error\)](<#New>)
  - [func \(c \*Client\[K, V\]\) Close\(\)](<#Client[K, V].Close>)
  - [func \(c \*Client\[K, V\]\) Del\(ctx context.Context, key K, opt ...DelOption\) \(res \*Response\[int\], err error\)](<#Client[K, V].Del>)
  - [func \(c \*Client\[K, V\]\) Get\(ctx context.Context, key K, opt ...GetOption\) \(res \*Response\[V\], err error\)](<#Client[K, V].Get>)
  - [func \(c \*Client\[K, V\]\) ID\(\) string](<#Client[K, V].ID>)
  - [func \(c \*Client\[K, V\]\) KeyNotify\(ctx context.Context, key K, opt ...KeyNotifyOption\) \(err error\)](<#Client[K, V].KeyNotify>)
  - [func \(c \*Client\[K, V\]\) KeyNotifyStop\(ctx context.Context, key K, opt ...KeyNotifyOption\) \(err error\)](<#Client[K, V].KeyNotifyStop>)
  - [func \(c \*Client\[K, V\]\) Notify\(key K\) \(\<\-chan Notify\[K, V\], func\(\)\)](<#Client[K, V].Notify>)
  - [func \(c \*Client\[K, V\]\) Set\(ctx context.Context, key K, val V, opt ...SetOption\) \(res \*Response\[bool\], err error\)](<#Client[K, V].Set>)
  - [func \(c \*Client\[K, V\]\) Start\(ctx context.Context\) error](<#Client[K, V].Start>)
  - [func \(c \*Client\[K, V\]\) VDel\(ctx context.Context, key K, val V, opt ...VDelOption\) \(res \*Response\[int\], err error\)](<#Client[K, V].VDel>)
- [type ClientOption](<#ClientOption>)
  - [func WithLogger\(logger \*slog.Logger\) ClientOption](<#WithLogger>)
- [type ClientOptions](<#ClientOptions>)
  - [func \(o \*ClientOptions\) Apply\(opts \[\]ClientOption, rest ...ClientOption\)](<#ClientOptions.Apply>)
- [type Condition](<#Condition>)
- [type DelOption](<#DelOption>)
- [type DelOptions](<#DelOptions>)
  - [func \(o \*DelOptions\) Apply\(opts \[\]DelOption, rest ...DelOption\)](<#DelOptions.Apply>)
- [type GetOption](<#GetOption>)
- [type GetOptions](<#GetOptions>)
  - [func \(o \*GetOptions\) Apply\(opts \[\]GetOption, rest ...GetOption\)](<#GetOptions.Apply>)
- [type KeyNotifyOption](<#KeyNotifyOption>)
- [type KeyNotifyOptions](<#KeyNotifyOptions>)
  - [func \(o \*KeyNotifyOptions\) Apply\(opts \[\]KeyNotifyOption, rest ...KeyNotifyOption\)](<#KeyNotifyOptions.Apply>)
- [type MqttClient](<#MqttClient>)
- [type Notify](<#Notify>)
- [type PayloadError](<#PayloadError>)
- [type Response](<#Response>)
- [type ServiceError](<#ServiceError>)
- [type SetOption](<#SetOption>)
- [type SetOptions](<#SetOptions>)
  - [func \(o \*SetOptions\) Apply\(opts \[\]SetOption, rest ...SetOption\)](<#SetOptions.Apply>)
- [type VDelOption](<#VDelOption>)
- [type VDelOptions](<#VDelOptions>)
  - [func \(o \*VDelOptions\) Apply\(opts \[\]VDelOption, rest ...VDelOption\)](<#VDelOptions.Apply>)
- [type WithConcurrency](<#WithConcurrency>)
- [type WithCondition](<#WithCondition>)
- [type WithExpiry](<#WithExpiry>)
- [type WithFencingToken](<#WithFencingToken>)
- [type WithManualAck](<#WithManualAck>)
- [type WithPersist](<#WithPersist>)
- [type WithTimeout](<#WithTimeout>)


## Variables

<a name="ErrService"></a>

```go
var (
    ErrService  = errors.ErrService
    ErrPayload  = errors.ErrPayload
    ErrArgument = errors.ErrArgument
)
```

<a name="ArgumentError"></a>
## type [ArgumentError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L70>)

ArgumentError indicates an invalid argument.

```go
type ArgumentError = errors.Argument
```

<a name="Bytes"></a>
## type [Bytes](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L25>)

Bytes represents generic byte data.

```go
type Bytes interface {
    // contains filtered or unexported methods
}
```

<a name="Client"></a>
## type [Client](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L28-L44>)

Client represents a client of the state store.

```go
type Client[K, V Bytes] struct {
    // contains filtered or unexported fields
}
```

<a name="New"></a>
### func [New](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L87-L91>)

```go
func New[K, V Bytes](app *protocol.Application, client MqttClient, opt ...ClientOption) (c *Client[K, V], err error)
```

New creates a new state store client. It takes the key and value types as parameters to avoid unnecessary casting; both may be string, \[\]byte, or equivalent types.

<a name="Client[K, V].Close"></a>
### func \(\*Client\[K, V\]\) [Close](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L166>)

```go
func (c *Client[K, V]) Close()
```

Close all underlying MQTT topics and free resources.

<a name="Client[K, V].Del"></a>
### func \(\*Client\[K, V\]\) [Del](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/del.go#L28-L32>)

```go
func (c *Client[K, V]) Del(ctx context.Context, key K, opt ...DelOption) (res *Response[int], err error)
```

Del deletes the given key. It returns the number of keys deleted \(typically 0 or 1\).

<a name="Client[K, V].Get"></a>
### func \(\*Client\[K, V\]\) [Get](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/get.go#L27-L31>)

```go
func (c *Client[K, V]) Get(ctx context.Context, key K, opt ...GetOption) (res *Response[V], err error)
```

Get the value and version of the given key. If the key is not present, it returns a fully zero response struct; if the key is present but empty, it returns an empty value and the stored version.

<a name="Client[K, V].ID"></a>
### func \(\*Client\[K, V\]\) [ID](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L172>)

```go
func (c *Client[K, V]) ID() string
```

ID returns the ID of the underlying MQTT client.

<a name="Client[K, V].KeyNotify"></a>
### func \(\*Client\[K, V\]\) [KeyNotify](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/keynotify.go#L27-L31>)

```go
func (c *Client[K, V]) KeyNotify(ctx context.Context, key K, opt ...KeyNotifyOption) (err error)
```

KeyNotify executes the notification request on the state store in order to begin receiving notifications. It should be paired with a KeyNotifyStop call.

<a name="Client[K, V].KeyNotifyStop"></a>
### func \(\*Client\[K, V\]\) [KeyNotifyStop](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/keynotify.go#L58-L62>)

```go
func (c *Client[K, V]) KeyNotifyStop(ctx context.Context, key K, opt ...KeyNotifyOption) (err error)
```

KeyNotifyStop executes the stop notification request on the state store in order to stop receiving notifications. It should only be called once per successfull call to KeyNotify \(but may be retried in case of failure\).

<a name="Client[K, V].Notify"></a>
### func \(\*Client\[K, V\]\) [Notify](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/notify.go#L34>)

```go
func (c *Client[K, V]) Notify(key K) (<-chan Notify[K, V], func())
```

Notify requests a notification channel for a key. It returns the channel and a function to remove and close that channel. Note that KeyNotify must be called to actually perform the notification request \(though notifications may be received on this channel if KeyNotify had already been called previously\). Also please note that the state store does not queue messages when the client is disconnected, therefore notifications received on this channel are not guaranteed, may be duplicated, and may come out\-of\-order during reconnection.

<a name="Client[K, V].Set"></a>
### func \(\*Client\[K, V\]\) [Set](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/set.go#L34-L39>)

```go
func (c *Client[K, V]) Set(ctx context.Context, key K, val V, opt ...SetOption) (res *Response[bool], err error)
```

Set the value of the given key. If the key is successfully set, it returns true and the new or updated version; if the key is not set due to the specified condition, it returns false and the stored version.

<a name="Client[K, V].Start"></a>
### func \(\*Client\[K, V\]\) [Start](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L161>)

```go
func (c *Client[K, V]) Start(ctx context.Context) error
```

Start listening to all underlying MQTT topics.

<a name="Client[K, V].VDel"></a>
### func \(\*Client\[K, V\]\) [VDel](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/vdel.go#L29-L34>)

```go
func (c *Client[K, V]) VDel(ctx context.Context, key K, val V, opt ...VDelOption) (res *Response[int], err error)
```

VDel deletes the given key if it is equal to the given value. It returns the number of values deleted \(typically 0 or 1\) or \-1 if the key was present but did not match the given value.

<a name="ClientOption"></a>
## type [ClientOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L47>)

ClientOption represents a single option for the client.

```go
type ClientOption interface {
    // contains filtered or unexported methods
}
```

<a name="WithLogger"></a>
### func [WithLogger](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L65>)

```go
func WithLogger(logger *slog.Logger) ClientOption
```

WithLogger enables logging with the provided slog logger.

<a name="ClientOptions"></a>
## type [ClientOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L50-L54>)

ClientOptions are the resolved options for the client.

```go
type ClientOptions struct {
    Concurrency uint
    ManualAck   bool
    Logger      *slog.Logger
}
```

<a name="ClientOptions.Apply"></a>
### func \(\*ClientOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L252-L255>)

```go
func (o *ClientOptions) Apply(opts []ClientOption, rest ...ClientOption)
```

Apply resolves the provided list of options.

<a name="Condition"></a>
## type [Condition](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L15>)

Condition specifies the conditions under which the key will be set.

```go
type Condition string
```

<a name="Always"></a>

```go
const (
    // Always indicates that the key should always be set to the provided value.
    // This is the default.
    Always Condition = ""

    // NotExists indicates that the key should only be set if it does not exist.
    NotExists Condition = "NX"

    // NotExistOrEqual indicates that the key should only be set if it does not
    // exist or is equal to the set value. This is typically used to update the
    // expiry on the key.
    NotExistsOrEqual Condition = "NEX"
)
```

<a name="DelOption"></a>
## type [DelOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/del.go#L17>)

DelOption represents a single option for the Del method.

```go
type DelOption interface {
    // contains filtered or unexported methods
}
```

<a name="DelOptions"></a>
## type [DelOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/del.go#L20-L23>)

DelOptions are the resolved options for the Del method.

```go
type DelOptions struct {
    FencingToken hlc.HybridLogicalClock
    Timeout      time.Duration
}
```

<a name="DelOptions.Apply"></a>
### func \(\*DelOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/del.go#L47>)

```go
func (o *DelOptions) Apply(opts []DelOption, rest ...DelOption)
```

Apply resolves the provided list of options.

<a name="GetOption"></a>
## type [GetOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/get.go#L16>)

GetOption represents a single option for the Get method.

```go
type GetOption interface {
    // contains filtered or unexported methods
}
```

<a name="GetOptions"></a>
## type [GetOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/get.go#L19-L21>)

GetOptions are the resolved options for the Get method.

```go
type GetOptions struct {
    Timeout time.Duration
}
```

<a name="GetOptions.Apply"></a>
### func \(\*GetOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/get.go#L46>)

```go
func (o *GetOptions) Apply(opts []GetOption, rest ...GetOption)
```

Apply resolves the provided list of options.

<a name="KeyNotifyOption"></a>
## type [KeyNotifyOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/keynotify.go#L17>)

KeyNotifyOption represents a single option for the KeyNotify method.

```go
type KeyNotifyOption interface {
    // contains filtered or unexported methods
}
```

<a name="KeyNotifyOptions"></a>
## type [KeyNotifyOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/keynotify.go#L20-L22>)

KeyNotifyOptions are the resolved options for the KeyNotify method.

```go
type KeyNotifyOptions struct {
    Timeout time.Duration
}
```

<a name="KeyNotifyOptions.Apply"></a>
### func \(\*KeyNotifyOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/keynotify.go#L92-L95>)

```go
func (o *KeyNotifyOptions) Apply(opts []KeyNotifyOption, rest ...KeyNotifyOption)
```

Apply resolves the provided list of options.

<a name="MqttClient"></a>
## type [MqttClient](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L72-L75>)



```go
type MqttClient interface {
    protocol.MqttClient
    RegisterConnectEventHandler(mqtt.ConnectEventHandler) func()
}
```

<a name="Notify"></a>
## type [Notify](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/notify.go#L16-L25>)

Notify represents a notification event.

```go
type Notify[K, V Bytes] struct {
    Key       K
    Operation string
    Value     V
    Version   hlc.HybridLogicalClock

    // Ack provides a function to manually ack if enabled; it will be nil
    // otherwise.
    Ack func()
}
```

<a name="PayloadError"></a>
## type [PayloadError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L68>)

PayloadError indicates a malformed or unexpected payload returned from the state store.

```go
type PayloadError = errors.Payload
```

<a name="Response"></a>
## type [Response](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L59-L62>)

Response represents a state store response, which will include a value depending on the method and the stored version returned for the key \(if any\).

```go
type Response[T any] struct {
    Value   T
    Version hlc.HybridLogicalClock
}
```

<a name="ServiceError"></a>
## type [ServiceError](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/client.go#L65>)

ServiceError indicates an error returned from the state store.

```go
type ServiceError = errors.Service
```

<a name="SetOption"></a>
## type [SetOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/set.go#L19>)

SetOption represents a single option for the Set method.

```go
type SetOption interface {
    // contains filtered or unexported methods
}
```

<a name="SetOptions"></a>
## type [SetOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/set.go#L22-L28>)

SetOptions are the resolved options for the Set method.

```go
type SetOptions struct {
    Expiry       time.Duration
    Condition    Condition
    FencingToken hlc.HybridLogicalClock
    Timeout      time.Duration
    Persist      bool
}
```

<a name="SetOptions.Apply"></a>
### func \(\*SetOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/set.go#L68>)

```go
func (o *SetOptions) Apply(opts []SetOption, rest ...SetOption)
```

Apply resolves the provided list of options.

<a name="VDelOption"></a>
## type [VDelOption](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/vdel.go#L17>)

VDelOption represents a single option for the VDel method.

```go
type VDelOption interface {
    // contains filtered or unexported methods
}
```

<a name="VDelOptions"></a>
## type [VDelOptions](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/vdel.go#L20-L23>)

VDelOptions are the resolved options for the VDel method.

```go
type VDelOptions struct {
    FencingToken hlc.HybridLogicalClock
    Timeout      time.Duration
}
```

<a name="VDelOptions.Apply"></a>
### func \(\*VDelOptions\) [Apply](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/vdel.go#L49>)

```go
func (o *VDelOptions) Apply(opts []VDelOption, rest ...VDelOption)
```

Apply resolves the provided list of options.

<a name="WithConcurrency"></a>
## type [WithConcurrency](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L33>)

WithConcurrency indicates how many notifications can execute in parallel.

```go
type WithConcurrency uint
```

<a name="WithCondition"></a>
## type [WithCondition](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L19>)

WithCondition indicates that the key should only be set under the given conditions.

```go
type WithCondition Condition
```

<a name="WithExpiry"></a>
## type [WithExpiry](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L23>)

WithExpiry indicates that the key should expire after the given duration \(with millisecond precision\).

```go
type WithExpiry time.Duration
```

<a name="WithFencingToken"></a>
## type [WithFencingToken](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L27>)

WithFencingToken adds a fencing token to the set request to provide lock ownership checking.

```go
type WithFencingToken hlc.HybridLogicalClock
```

<a name="WithManualAck"></a>
## type [WithManualAck](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L36>)

WithManualAck allows notifications to be manually acknowledged.

```go
type WithManualAck bool
```

<a name="WithPersist"></a>
## type [WithPersist](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L39>)

WithPersist indicates that the key should be stored to disk.

```go
type WithPersist bool
```

<a name="WithTimeout"></a>
## type [WithTimeout](<https://github.com/Azure/iot-operations-sdks/blob/main/go/services/statestore/options.go#L30>)

WithTimeout adds a timeout to the request \(with second precision\).

```go
type WithTimeout time.Duration
```

Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
