cachestorage.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // Package cachestorage provides the Chrome DevTools Protocol
  2. // commands, types, and events for the CacheStorage domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package cachestorage
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. "github.com/chromedp/cdproto/storage"
  11. )
  12. // DeleteCacheParams deletes a cache.
  13. type DeleteCacheParams struct {
  14. CacheID CacheID `json:"cacheId"` // Id of cache for deletion.
  15. }
  16. // DeleteCache deletes a cache.
  17. //
  18. // See: https://chromedevtools.github.io/devtools-protocol/tot/CacheStorage#method-deleteCache
  19. //
  20. // parameters:
  21. //
  22. // cacheID - Id of cache for deletion.
  23. func DeleteCache(cacheID CacheID) *DeleteCacheParams {
  24. return &DeleteCacheParams{
  25. CacheID: cacheID,
  26. }
  27. }
  28. // Do executes CacheStorage.deleteCache against the provided context.
  29. func (p *DeleteCacheParams) Do(ctx context.Context) (err error) {
  30. return cdp.Execute(ctx, CommandDeleteCache, p, nil)
  31. }
  32. // DeleteEntryParams deletes a cache entry.
  33. type DeleteEntryParams struct {
  34. CacheID CacheID `json:"cacheId"` // Id of cache where the entry will be deleted.
  35. Request string `json:"request"` // URL spec of the request.
  36. }
  37. // DeleteEntry deletes a cache entry.
  38. //
  39. // See: https://chromedevtools.github.io/devtools-protocol/tot/CacheStorage#method-deleteEntry
  40. //
  41. // parameters:
  42. //
  43. // cacheID - Id of cache where the entry will be deleted.
  44. // request - URL spec of the request.
  45. func DeleteEntry(cacheID CacheID, request string) *DeleteEntryParams {
  46. return &DeleteEntryParams{
  47. CacheID: cacheID,
  48. Request: request,
  49. }
  50. }
  51. // Do executes CacheStorage.deleteEntry against the provided context.
  52. func (p *DeleteEntryParams) Do(ctx context.Context) (err error) {
  53. return cdp.Execute(ctx, CommandDeleteEntry, p, nil)
  54. }
  55. // RequestCacheNamesParams requests cache names.
  56. type RequestCacheNamesParams struct {
  57. SecurityOrigin string `json:"securityOrigin,omitempty,omitzero"` // At least and at most one of securityOrigin, storageKey, storageBucket must be specified. Security origin.
  58. StorageKey string `json:"storageKey,omitempty,omitzero"` // Storage key.
  59. StorageBucket *storage.Bucket `json:"storageBucket,omitempty,omitzero"` // Storage bucket. If not specified, it uses the default bucket.
  60. }
  61. // RequestCacheNames requests cache names.
  62. //
  63. // See: https://chromedevtools.github.io/devtools-protocol/tot/CacheStorage#method-requestCacheNames
  64. //
  65. // parameters:
  66. func RequestCacheNames() *RequestCacheNamesParams {
  67. return &RequestCacheNamesParams{}
  68. }
  69. // WithSecurityOrigin at least and at most one of securityOrigin, storageKey,
  70. // storageBucket must be specified. Security origin.
  71. func (p RequestCacheNamesParams) WithSecurityOrigin(securityOrigin string) *RequestCacheNamesParams {
  72. p.SecurityOrigin = securityOrigin
  73. return &p
  74. }
  75. // WithStorageKey storage key.
  76. func (p RequestCacheNamesParams) WithStorageKey(storageKey string) *RequestCacheNamesParams {
  77. p.StorageKey = storageKey
  78. return &p
  79. }
  80. // WithStorageBucket storage bucket. If not specified, it uses the default
  81. // bucket.
  82. func (p RequestCacheNamesParams) WithStorageBucket(storageBucket *storage.Bucket) *RequestCacheNamesParams {
  83. p.StorageBucket = storageBucket
  84. return &p
  85. }
  86. // RequestCacheNamesReturns return values.
  87. type RequestCacheNamesReturns struct {
  88. Caches []*Cache `json:"caches,omitempty,omitzero"` // Caches for the security origin.
  89. }
  90. // Do executes CacheStorage.requestCacheNames against the provided context.
  91. //
  92. // returns:
  93. //
  94. // caches - Caches for the security origin.
  95. func (p *RequestCacheNamesParams) Do(ctx context.Context) (caches []*Cache, err error) {
  96. // execute
  97. var res RequestCacheNamesReturns
  98. err = cdp.Execute(ctx, CommandRequestCacheNames, p, &res)
  99. if err != nil {
  100. return nil, err
  101. }
  102. return res.Caches, nil
  103. }
  104. // RequestCachedResponseParams fetches cache entry.
  105. type RequestCachedResponseParams struct {
  106. CacheID CacheID `json:"cacheId"` // Id of cache that contains the entry.
  107. RequestURL string `json:"requestURL"` // URL spec of the request.
  108. RequestHeaders []*Header `json:"requestHeaders"` // headers of the request.
  109. }
  110. // RequestCachedResponse fetches cache entry.
  111. //
  112. // See: https://chromedevtools.github.io/devtools-protocol/tot/CacheStorage#method-requestCachedResponse
  113. //
  114. // parameters:
  115. //
  116. // cacheID - Id of cache that contains the entry.
  117. // requestURL - URL spec of the request.
  118. // requestHeaders - headers of the request.
  119. func RequestCachedResponse(cacheID CacheID, requestURL string, requestHeaders []*Header) *RequestCachedResponseParams {
  120. return &RequestCachedResponseParams{
  121. CacheID: cacheID,
  122. RequestURL: requestURL,
  123. RequestHeaders: requestHeaders,
  124. }
  125. }
  126. // RequestCachedResponseReturns return values.
  127. type RequestCachedResponseReturns struct {
  128. Response *CachedResponse `json:"response,omitempty,omitzero"` // Response read from the cache.
  129. }
  130. // Do executes CacheStorage.requestCachedResponse against the provided context.
  131. //
  132. // returns:
  133. //
  134. // response - Response read from the cache.
  135. func (p *RequestCachedResponseParams) Do(ctx context.Context) (response *CachedResponse, err error) {
  136. // execute
  137. var res RequestCachedResponseReturns
  138. err = cdp.Execute(ctx, CommandRequestCachedResponse, p, &res)
  139. if err != nil {
  140. return nil, err
  141. }
  142. return res.Response, nil
  143. }
  144. // RequestEntriesParams requests data from cache.
  145. type RequestEntriesParams struct {
  146. CacheID CacheID `json:"cacheId"` // ID of cache to get entries from.
  147. SkipCount int64 `json:"skipCount,omitempty,omitzero"` // Number of records to skip.
  148. PageSize int64 `json:"pageSize,omitempty,omitzero"` // Number of records to fetch.
  149. PathFilter string `json:"pathFilter,omitempty,omitzero"` // If present, only return the entries containing this substring in the path
  150. }
  151. // RequestEntries requests data from cache.
  152. //
  153. // See: https://chromedevtools.github.io/devtools-protocol/tot/CacheStorage#method-requestEntries
  154. //
  155. // parameters:
  156. //
  157. // cacheID - ID of cache to get entries from.
  158. func RequestEntries(cacheID CacheID) *RequestEntriesParams {
  159. return &RequestEntriesParams{
  160. CacheID: cacheID,
  161. }
  162. }
  163. // WithSkipCount number of records to skip.
  164. func (p RequestEntriesParams) WithSkipCount(skipCount int64) *RequestEntriesParams {
  165. p.SkipCount = skipCount
  166. return &p
  167. }
  168. // WithPageSize number of records to fetch.
  169. func (p RequestEntriesParams) WithPageSize(pageSize int64) *RequestEntriesParams {
  170. p.PageSize = pageSize
  171. return &p
  172. }
  173. // WithPathFilter if present, only return the entries containing this
  174. // substring in the path.
  175. func (p RequestEntriesParams) WithPathFilter(pathFilter string) *RequestEntriesParams {
  176. p.PathFilter = pathFilter
  177. return &p
  178. }
  179. // RequestEntriesReturns return values.
  180. type RequestEntriesReturns struct {
  181. CacheDataEntries []*DataEntry `json:"cacheDataEntries,omitempty,omitzero"` // Array of object store data entries.
  182. ReturnCount float64 `json:"returnCount,omitempty,omitzero"` // Count of returned entries from this storage. If pathFilter is empty, it is the count of all entries from this storage.
  183. }
  184. // Do executes CacheStorage.requestEntries against the provided context.
  185. //
  186. // returns:
  187. //
  188. // cacheDataEntries - Array of object store data entries.
  189. // returnCount - Count of returned entries from this storage. If pathFilter is empty, it is the count of all entries from this storage.
  190. func (p *RequestEntriesParams) Do(ctx context.Context) (cacheDataEntries []*DataEntry, returnCount float64, err error) {
  191. // execute
  192. var res RequestEntriesReturns
  193. err = cdp.Execute(ctx, CommandRequestEntries, p, &res)
  194. if err != nil {
  195. return nil, 0, err
  196. }
  197. return res.CacheDataEntries, res.ReturnCount, nil
  198. }
  199. // Command names.
  200. const (
  201. CommandDeleteCache = "CacheStorage.deleteCache"
  202. CommandDeleteEntry = "CacheStorage.deleteEntry"
  203. CommandRequestCacheNames = "CacheStorage.requestCacheNames"
  204. CommandRequestCachedResponse = "CacheStorage.requestCachedResponse"
  205. CommandRequestEntries = "CacheStorage.requestEntries"
  206. )