Skip to content

Commit

Permalink
feat: add CallContext.{GetKeyData,SetKeyData,HasKeyData} APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
y1yang0 committed Aug 7, 2024
1 parent f1fe323 commit 0b31235
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type CallContext interface {
SetData(interface{})
// Get the data field, can be used to pass information between OnEnter&OnExit
GetData() interface{}
// Get the map data field by key
GetKeyData(key string) interface{}
// Set the map data field by key
SetKeyData(key string, val interface{})
// Has the map data field by key
HasKeyData(key string) bool
// Get the original function parameter at index idx
GetParam(idx int) interface{}
// Change the original function parameter at index idx
Expand Down
21 changes: 21 additions & 0 deletions tool/instrument/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ func (c *CallContextImpl) SetSkipCall(skip bool) { c.SkipCall = skip }
func (c *CallContextImpl) IsSkipCall() bool { return c.SkipCall }
func (c *CallContextImpl) SetData(data interface{}) { c.Data = data }
func (c *CallContextImpl) GetData() interface{} { return c.Data }
func (c *CallContextImpl) GetKeyData(key string) interface{} {
if data == nil {
return nil
}
return data.(map[string]interface{})[key]
}
func (c *CallContextImpl) SetKeyData(key string, val interface{}) {
if data == nil {
data = make(map[string]interface{})
}
data.(map[string]interface{})[key] = val
}

func (c *CallContextImpl) HasKeyData(key string) bool {
if data == nil {
return false
}
_, ok := data.(map[string]interface{})[key]
return ok
}

func (c *CallContextImpl) GetParam(idx int) interface{} {
switch idx {
}
Expand Down

0 comments on commit 0b31235

Please sign in to comment.