blob: f8b83fbe4ce1ab93150b59dae59a5af716febf08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package core
import "context"
type StateBackend interface {
// SetCurrentKey will perform in Memory
SetCurrentKey(key string) error
// GetCurrentKey will perform in Memory
GetCurrentKey() string
// GetValueState will perform in disk
GetValueState(ctx context.Context, key string) (ValueState[any], error)
}
type stateBackendKeyType struct{}
var stateBackendKey stateBackendKeyType
func InjectStateBackend(ctx context.Context, state StateBackend) context.Context {
return context.WithValue(ctx, stateBackendKey, state)
}
func ExtractStateBackend(ctx context.Context) (StateBackend, bool) {
backend, ok := ctx.Value(stateBackendKey).(StateBackend)
return backend, ok
}
|