Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 200cab6

Browse files
committed
feat: add GetRootContextByID call
1 parent 72ffe0f commit 200cab6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

proxywasm/vmstate.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
package proxywasm
1616

17+
import (
18+
"errors"
19+
"fmt"
20+
)
21+
1722
type (
1823
HttpCalloutCallBack = func(numHeaders, bodySize, numTrailers int)
1924

@@ -57,6 +62,16 @@ func SetNewStreamContext(f func(rootContextID, contextID uint32) StreamContext)
5762
currentState.newStreamContext = f
5863
}
5964

65+
var ErrorRootContextNotFound = errors.New("root context not found")
66+
67+
func GetRootContextByID(rootContextID uint32) (RootContext, error) {
68+
rootContextState, ok := currentState.rootContexts[rootContextID]
69+
if !ok {
70+
return nil, fmt.Errorf("%w: %d", ErrorRootContextNotFound, rootContextID)
71+
}
72+
return rootContextState.context, nil
73+
}
74+
6075
//go:inline
6176
func (s *state) createRootContext(contextID uint32) {
6277
var ctx RootContext

0 commit comments

Comments
 (0)