@@ -7,12 +7,48 @@ import (
7
7
"github.com/michaeldcanady/servicenow-sdk-go/internal"
8
8
)
9
9
10
- // TablePageIterato2[T] is an iterator over pages of table entries.
10
+ // TablePageIterator is a generic struct in Golang which is used to iterate over pages of entries.
11
+ // It embeds the core.PageIterator2 struct and can be used with any type that satisfies the Entry interface.
12
+ //
13
+ // Fields:
14
+ // - core.PageIterator2[T]: This is an embedded field of type PageIterator2 from the core package.
15
+ // The type T represents the type of Entry that the iterator will return.
16
+ //
17
+ // Usage:
18
+ // You can use this struct to iterate over pages of entries in a table.
19
+ // The specific type of Entry depends on what you specify for T when you create an instance of TablePageIterator.
11
20
type TablePageIterator [T Entry ] struct {
12
- // pageIterator is the core page iterator that this table page iterator wraps.
13
- pageIterator core.PageIterator2 [T ]
21
+ * core.PageIterator2 [T ]
14
22
}
15
23
24
+ // constructTableCollection is a generic function in Golang used to construct a collection of table entries.
25
+ // It takes an http.Response pointer as input and returns a CollectionResponse of the specified Entry type and an error.
26
+ //
27
+ // Parameters:
28
+ // * response: This is a pointer to an http.Response that contains the server's response to an HTTP request.
29
+ //
30
+ // Returns:
31
+ // * core.CollectionResponse[T]: This is a CollectionResponse of the specified Entry type. It represents the collection of table entries.
32
+ // * error: This is an error that will be returned if there is any error while parsing the response.
33
+ //
34
+ // Usage:
35
+ // You can use this function to construct a collection of table entries from an *http.Response.
36
+ //
37
+ // func ExampleConstructTableCollectionF() {
38
+ // response, err := http.Get("http://example.com")
39
+ //
40
+ // if err != nil {
41
+ // log.Fatal(err)
42
+ // }
43
+ //
44
+ // collection, err := constructTableCollection[MyEntryType](response)
45
+ //
46
+ // if err != nil {
47
+ // log.Fatal(err)
48
+ // }
49
+ //
50
+ // // Process collection
51
+ // }
16
52
func constructTableCollection [T Entry ](response * http.Response ) (core.CollectionResponse [T ], error ) {
17
53
resp := & TableCollectionResponse2 [T ]{}
18
54
@@ -23,14 +59,40 @@ func constructTableCollection[T Entry](response *http.Response) (core.Collection
23
59
return resp , nil
24
60
}
25
61
26
- // NewTablePageIterator[T] creates a new TablePageIterator2 instance.
62
+ // NewTablePageIterator is a function that creates a new instance of TablePageIterator.
63
+ // It takes a TableCollectionResponse and a Client as input and returns a pointer to a TablePageIterator and an error.
64
+ //
65
+ // Parameters:
66
+ //
67
+ // - collection: This is a pointer to a TableCollectionResponse that contains the collection of table entries.
68
+ // - client: This is a Client that will be used to make requests to the server.
69
+ //
70
+ // Returns:
71
+ //
72
+ // - *TablePageIterator[T]: This is a pointer to a TablePageIterator that can be used to iterate over the pages of entries in the collection.
73
+ // - error: This is an error that will be returned if there is any error while creating the PageIterator.
74
+ //
75
+ // Usage:
76
+ // You can use this function to create a new instance of TablePageIterator.
77
+ //
78
+ // func ExampleNewTablePageIteratorF() {
79
+ // // use an existing collection
80
+ // var collection TableCollectionResponse2[T]
81
+ // // use a new or existing client
82
+ // var client core.Client
83
+ // iter, err := NewTablePageIterator[T](collection, client)
84
+ // if err != nil {
85
+ // log.Fatal(err)
86
+ // }
87
+ // // Use iter to iterate over the pages of entries
88
+ // }
27
89
func NewTablePageIterator [T Entry ](collection * TableCollectionResponse2 [T ], client core.Client ) (* TablePageIterator [T ], error ) {
28
90
pageIterator , err := core .NewPageIterator2 [T ](collection , client , constructTableCollection [T ])
29
91
if err != nil {
30
92
return nil , err
31
93
}
32
94
33
95
return & TablePageIterator [T ]{
34
- pageIterator : ( * pageIterator ) ,
96
+ pageIterator ,
35
97
}, nil
36
98
}
0 commit comments