MCPcopy
hub / github.com/mxschmitt/playwright-go / transformStructIntoMapIfNeeded

Function transformStructIntoMapIfNeeded

helpers.go:55–93  ·  view source on GitHub ↗
(inStruct any)

Source from the content-addressed store, hash-verified

53}
54
55func transformStructIntoMapIfNeeded(inStruct any) map[string]any {
56 out := make(map[string]any)
57 v := reflect.ValueOf(inStruct)
58 if v.Kind() == reflect.Pointer {
59 v = v.Elem()
60 }
61 typ := v.Type()
62 if v.Kind() == reflect.Struct {
63 // Merge into the base map by the JSON struct tag
64 for i := 0; i < v.NumField(); i++ {
65 fi := typ.Field(i)
66 tagv := fi.Tag.Get("json")
67 key := strings.Split(tagv, ",")[0]
68 if key == "" {
69 key = fi.Name
70 }
71 // Special handling for timeout field: provide default value when nil
72 // This is required in Playwright v1.57+ protocol where timeout is no longer optional
73 if key == "timeout" && skipFieldSerialization(v.Field(i)) {
74 out[key] = float64(30000) // default 30s
75 continue
76 }
77 // Skip the values when the field is a pointer (like *string) and nil.
78 if fi.IsExported() && !skipFieldSerialization(v.Field(i)) {
79 // We use the JSON struct fields for getting the original names
80 // out of the field.
81 out[key] = transformStructValues(v.Field(i).Interface())
82 }
83 }
84 } else if v.Kind() == reflect.Map {
85 // Merge into the base map
86 for _, key := range v.MapKeys() {
87 if !skipFieldSerialization(v.MapIndex(key)) {
88 out[key.String()] = transformStructValues(v.MapIndex(key).Interface())
89 }
90 }
91 }
92 return out
93}
94
95// transformOptions handles the parameter data transformation
96func transformOptions(options ...any) map[string]any {

Callers 2

transformStructValuesFunction · 0.85
transformOptionsFunction · 0.85

Calls 5

skipFieldSerializationFunction · 0.85
transformStructValuesFunction · 0.85
TypeMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected