MCPcopy
hub / github.com/gofiber/fiber / GetWithContext

Method GetWithContext

shared_state.go:99–118  ·  view source on GitHub ↗

GetWithContext returns a defensive copy of the stored bytes so callers can safely mutate the returned slice without changing the shared value.

(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

97// GetWithContext returns a defensive copy of the stored bytes so callers can
98// safely mutate the returned slice without changing the shared value.
99func (s *SharedState) GetWithContext(ctx context.Context, key string) ([]byte, bool, error) { //nolint:gocritic // Keep unnamed returns for clarity.
100 if err := s.ensureStorage(); err != nil {
101 return nil, false, err
102 }
103
104 storageKey, ok := s.storageKey(key)
105 if !ok {
106 return nil, false, nil
107 }
108
109 data, err := s.storage.GetWithContext(ctx, storageKey)
110 if err != nil {
111 return nil, false, err
112 }
113 if data == nil {
114 return nil, false, nil
115 }
116
117 return append([]byte(nil), data...), true, nil
118}
119
120func (s *SharedState) SetJSON(key string, v any, ttl time.Duration) error {
121 return s.SetJSONWithContext(context.Background(), key, v, ttl)

Callers 1

GetMethod · 0.95

Calls 3

ensureStorageMethod · 0.95
storageKeyMethod · 0.95
GetWithContextMethod · 0.65

Tested by

no test coverage detected