-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
type_helpers.go
72 lines (63 loc) · 1.79 KB
/
type_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package playwright
// String is a helper routine that allocates a new string value
// to store v and returns a pointer to it.
func String(v string) *string {
return &v
}
// Bool is a helper routine that allocates a new bool value
// to store v and returns a pointer to it.
func Bool(v bool) *bool {
return &v
}
// Int is a helper routine that allocates a new int32 value
// to store v and returns a pointer to it.
func Int(v int) *int {
return &v
}
// Float is a helper routine that allocates a new float64 value
// to store v and returns a pointer to it.
func Float(v float64) *float64 {
return &v
}
// Null will be used in certain scenarios where a strict nil pointer
// check is not possible
func Null() interface{} {
return "PW_NULL"
}
// StringSlice is a helper routine that allocates a new StringSlice value
// to store v and returns a pointer to it.
func StringSlice(v ...string) *[]string {
var o []string
o = append(o, v...)
return &o
}
// IntSlice is a helper routine that allocates a new IntSlice value
// to store v and returns a pointer to it.
func IntSlice(v ...int) *[]int {
var o []int
o = append(o, v...)
return &o
}
// ToOptionalStorageState converts StorageState to OptionalStorageState for use directly in [Browser.NewContext]
func (s StorageState) ToOptionalStorageState() *OptionalStorageState {
cookies := make([]OptionalCookie, len(s.Cookies))
for i, c := range s.Cookies {
cookies[i] = c.ToOptionalCookie()
}
return &OptionalStorageState{
Origins: s.Origins,
Cookies: cookies,
}
}
func (c Cookie) ToOptionalCookie() OptionalCookie {
return OptionalCookie{
Name: c.Name,
Value: c.Value,
Domain: String(c.Domain),
Path: String(c.Path),
Expires: Float(c.Expires),
HttpOnly: Bool(c.HttpOnly),
Secure: Bool(c.Secure),
SameSite: c.SameSite,
}
}