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

Function newSharedState

shared_state.go:32–74  ·  view source on GitHub ↗
(cfg *Config)

Source from the content-addressed store, hash-verified

30}
31
32func newSharedState(cfg *Config) *SharedState {
33 if cfg == nil {
34 cfg = &Config{}
35 }
36
37 prefix := cfg.SharedStatePrefix
38 if prefix == "" {
39 prefix = defaultSharedStatePrefix
40 if cfg.AppName != "" {
41 prefix += cfg.AppName + "-"
42 }
43 }
44
45 jsonEncoder := cfg.JSONEncoder
46 if jsonEncoder == nil {
47 jsonEncoder = json.Marshal
48 }
49 jsonDecoder := cfg.JSONDecoder
50 if jsonDecoder == nil {
51 jsonDecoder = json.Unmarshal
52 }
53 xmlEncoder := cfg.XMLEncoder
54 if xmlEncoder == nil {
55 xmlEncoder = xml.Marshal
56 }
57 xmlDecoder := cfg.XMLDecoder
58 if xmlDecoder == nil {
59 xmlDecoder = xml.Unmarshal
60 }
61
62 return &SharedState{
63 storage: cfg.SharedStorage,
64 jsonEncoder: jsonEncoder,
65 jsonDecoder: jsonDecoder,
66 msgPackEncoder: cfg.MsgPackEncoder,
67 msgPackDecoder: cfg.MsgPackDecoder,
68 cborEncoder: cfg.CBOREncoder,
69 cborDecoder: cfg.CBORDecoder,
70 xmlEncoder: xmlEncoder,
71 xmlDecoder: xmlDecoder,
72 prefix: prefix,
73 }
74}
75
76func (s *SharedState) Set(key string, val []byte, ttl time.Duration) error {
77 return s.SetWithContext(context.Background(), key, val, ttl)

Callers 2

NewFunction · 0.85

Calls

no outgoing calls

Tested by 1