Debian Codegraph @

acceleratedmobilepageurl/v1/acceleratedmobilepageurl-gen.go

raw symbols SCIP
1 // Copyright 2026 Google LLC.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Code generated file. DO NOT EDIT.
6
7 // Package acceleratedmobilepageurl provides access to the Accelerated Mobile Pages (AMP) URL API.
8 //
9 // For product documentation, see: https://developers.google.com/amp/cache/
10 //
11 // # Library status
12 //
13 // These client libraries are officially supported by Google. However, this
14 // library is considered complete and is in maintenance mode. This means
15 // that we will address critical bugs and security issues but will not add
16 // any new features.
17 //
18 // When possible, we recommend using our newer
19 // [Cloud Client Libraries for Go](https://pkg.go.dev/cloud.google.com/go)
20 // that are still actively being worked and iterated on.
21 //
22 // # Creating a client
23 //
24 // Usage example:
25 //
26 // import "google.golang.org/api/acceleratedmobilepageurl/v1"
27 // ...
28 // ctx := context.Background()
29 // acceleratedmobilepageurlService, err := acceleratedmobilepageurl.NewService(ctx)
30 //
31 // In this example, Google Application Default Credentials are used for
32 // authentication. For information on how to create and obtain Application
33 // Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
34 //
35 // # Other authentication options
36 //
37 // To use an API key for authentication (note: some APIs do not support API
38 // keys), use [google.golang.org/api/option.WithAPIKey]:
39 //
40 // acceleratedmobilepageurlService, err := acceleratedmobilepageurl.NewService(ctx, option.WithAPIKey("AIza..."))
41 //
42 // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth
43 // flow, use [google.golang.org/api/option.WithTokenSource]:
44 //
45 // config := &oauth2.Config{...}
46 // // ...
47 // token, err := config.Exchange(ctx, ...)
48 // acceleratedmobilepageurlService, err := acceleratedmobilepageurl.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
49 //
50 // See [google.golang.org/api/option.ClientOption] for details on options.
51 package acceleratedmobilepageurl // import "google.golang.org/api/acceleratedmobilepageurl/v1"
52
53 import (
54 "bytes"
55 "context"
56 "encoding/json"
57 "errors"
58 "fmt"
59 "io"
60 "log/slog"
61 "net/http"
62 "net/url"
63 "strconv"
64 "strings"
65
66 "github.com/googleapis/gax-go/v2/internallog"
67 googleapi "google.golang.org/api/googleapi"
68 internal "google.golang.org/api/internal"
69 gensupport "google.golang.org/api/internal/gensupport"
70 option "google.golang.org/api/option"
71 internaloption "google.golang.org/api/option/internaloption"
72 htransport "google.golang.org/api/transport/http"
73 )
74
75 // Always reference these packages, just in case the auto-generated code
76 // below doesn't.
77 var _ = bytes.NewBuffer
78 var _ = strconv.Itoa
79 var _ = fmt.Sprintf
80 var _ = json.NewDecoder
81 var _ = io.Copy
82 var _ = url.Parse
83 var _ = gensupport.MarshalJSON
84 var _ = googleapi.Version
85 var _ = errors.New
86 var _ = strings.Replace
87 var _ = context.Canceled
88 var _ = internaloption.WithDefaultEndpoint
89 var _ = internal.Version
90 var _ = internallog.New
91
92 const apiId = "acceleratedmobilepageurl:v1"
93 const apiName = "acceleratedmobilepageurl"
94 const apiVersion = "v1"
95 const basePath = "https://acceleratedmobilepageurl.googleapis.com/"
96 const basePathTemplate = "https://acceleratedmobilepageurl.UNIVERSE_DOMAIN/"
97 const mtlsBasePath = "https://acceleratedmobilepageurl.mtls.googleapis.com/"
98
99 // NewService creates a new Service.
100 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
101 opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
102 opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))
103 opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))
104 opts = append(opts, internaloption.EnableNewAuthLibrary())
105 client, endpoint, err := htransport.NewClient(ctx, opts...)
106 if err != nil {
107 return nil, err
108 }
109 s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)}
110 s.AmpUrls = NewAmpUrlsService(s)
111 if endpoint != "" {
112 s.BasePath = endpoint
113 }
114 return s, nil
115 }
116
117 // New creates a new Service. It uses the provided http.Client for requests.
118 //
119 // Deprecated: please use NewService instead.
120 // To provide a custom HTTP client, use option.WithHTTPClient.
121 // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
122 func New(client *http.Client) (*Service, error) {
123 if client == nil {
124 return nil, errors.New("client is nil")
125 }
126 return NewService(context.TODO(), option.WithHTTPClient(client))
127 }
128
129 type Service struct {
130 client *http.Client
131 logger *slog.Logger
132 BasePath string // API endpoint base URL
133 UserAgent string // optional additional User-Agent fragment
134
135 AmpUrls *AmpUrlsService
136 }
137
138 func (s *Service) userAgent() string {
139 if s.UserAgent == "" {
140 return googleapi.UserAgent
141 }
142 return googleapi.UserAgent + " " + s.UserAgent
143 }
144
145 func NewAmpUrlsService(s *Service) *AmpUrlsService {
146 rs := &AmpUrlsService{s: s}
147 return rs
148 }
149
150 type AmpUrlsService struct {
151 s *Service
152 }
153
154 // AmpUrl: AMP URL response for a requested URL.
155 type AmpUrl struct {
156 // AmpUrl: The AMP URL pointing to the publisher's web server.
157 AmpUrl string `json:"ampUrl,omitempty"`
158 // CdnAmpUrl: The AMP Cache URL (/amp/cache/overview#amp-cache-url-format)
159 // pointing to the cached document in the Google AMP Cache.
160 CdnAmpUrl string `json:"cdnAmpUrl,omitempty"`
161 // OriginalUrl: The original non-AMP URL.
162 OriginalUrl string `json:"originalUrl,omitempty"`
163 // ForceSendFields is a list of field names (e.g. "AmpUrl") to unconditionally
164 // include in API requests. By default, fields with empty or default values are
165 // omitted from API requests. See
166 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
167 // details.
168 ForceSendFields []string `json:"-"`
169 // NullFields is a list of field names (e.g. "AmpUrl") to include in API
170 // requests with the JSON null value. By default, fields with empty values are
171 // omitted from API requests. See
172 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
173 NullFields []string `json:"-"`
174 }
175
176 func (s AmpUrl) MarshalJSON() ([]byte, error) {
177 type NoMethod AmpUrl
178 return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields)
179 }
180
181 // AmpUrlError: AMP URL Error resource for a requested URL that couldn't be
182 // found.
183 type AmpUrlError struct {
184 // ErrorCode: The error code of an API call.
185 //
186 // Possible values:
187 // "ERROR_CODE_UNSPECIFIED" - Not specified error.
188 // "INPUT_URL_NOT_FOUND" - Indicates the requested URL is not found in the
189 // index, possibly because it's unable to be found, not able to be accessed by
190 // Googlebot, or some other error.
191 // "NO_AMP_URL" - Indicates no AMP URL has been found that corresponds to the
192 // requested URL.
193 // "APPLICATION_ERROR" - Indicates some kind of application error occurred at
194 // the server. Client advised to retry.
195 // "URL_IS_VALID_AMP" - DEPRECATED: Indicates the requested URL is a valid
196 // AMP URL. This is a non-error state, should not be relied upon as a sign of
197 // success or failure. It will be removed in future versions of the API.
198 // "URL_IS_INVALID_AMP" - Indicates that an AMP URL has been found that
199 // corresponds to the request URL, but it is not valid AMP HTML.
200 ErrorCode string `json:"errorCode,omitempty"`
201 // ErrorMessage: An optional descriptive error message.
202 ErrorMessage string `json:"errorMessage,omitempty"`
203 // OriginalUrl: The original non-AMP URL.
204 OriginalUrl string `json:"originalUrl,omitempty"`
205 // ForceSendFields is a list of field names (e.g. "ErrorCode") to
206 // unconditionally include in API requests. By default, fields with empty or
207 // default values are omitted from API requests. See
208 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
209 // details.
210 ForceSendFields []string `json:"-"`
211 // NullFields is a list of field names (e.g. "ErrorCode") to include in API
212 // requests with the JSON null value. By default, fields with empty values are
213 // omitted from API requests. See
214 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
215 NullFields []string `json:"-"`
216 }
217
218 func (s AmpUrlError) MarshalJSON() ([]byte, error) {
219 type NoMethod AmpUrlError
220 return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields)
221 }
222
223 // BatchGetAmpUrlsRequest: AMP URL request for a batch of URLs.
224 type BatchGetAmpUrlsRequest struct {
225 // LookupStrategy: The lookup_strategy being requested.
226 //
227 // Possible values:
228 // "FETCH_LIVE_DOC" - FETCH_LIVE_DOC strategy involves live document fetch of
229 // URLs not found in the index. Any request URL not found in the index is
230 // crawled in realtime to validate if there is a corresponding AMP URL. This
231 // strategy has higher coverage but with extra latency introduced by realtime
232 // crawling. This is the default strategy. Applications using this strategy
233 // should set higher HTTP timeouts of the API calls.
234 // "IN_INDEX_DOC" - IN_INDEX_DOC strategy skips fetching live documents of
235 // URL(s) not found in index. For applications which need low latency use of
236 // IN_INDEX_DOC strategy is recommended.
237 LookupStrategy string `json:"lookupStrategy,omitempty"`
238 // Urls: List of URLs to look up for the paired AMP URLs. The URLs are
239 // case-sensitive. Up to 50 URLs per lookup (see Usage Limits
240 // (/amp/cache/reference/limits)).
241 Urls []string `json:"urls,omitempty"`
242 // ForceSendFields is a list of field names (e.g. "LookupStrategy") to
243 // unconditionally include in API requests. By default, fields with empty or
244 // default values are omitted from API requests. See
245 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
246 // details.
247 ForceSendFields []string `json:"-"`
248 // NullFields is a list of field names (e.g. "LookupStrategy") to include in
249 // API requests with the JSON null value. By default, fields with empty values
250 // are omitted from API requests. See
251 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
252 NullFields []string `json:"-"`
253 }
254
255 func (s BatchGetAmpUrlsRequest) MarshalJSON() ([]byte, error) {
256 type NoMethod BatchGetAmpUrlsRequest
257 return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields)
258 }
259
260 // BatchGetAmpUrlsResponse: Batch AMP URL response.
261 type BatchGetAmpUrlsResponse struct {
262 // AmpUrls: For each URL in BatchAmpUrlsRequest, the URL response. The response
263 // might not be in the same order as URLs in the batch request. If
264 // BatchAmpUrlsRequest contains duplicate URLs, AmpUrl is generated only once.
265 AmpUrls []*AmpUrl `json:"ampUrls,omitempty"`
266 // UrlErrors: The errors for requested URLs that have no AMP URL.
267 UrlErrors []*AmpUrlError `json:"urlErrors,omitempty"`
268
269 // ServerResponse contains the HTTP response code and headers from the server.
270 googleapi.ServerResponse `json:"-"`
271 // ForceSendFields is a list of field names (e.g. "AmpUrls") to unconditionally
272 // include in API requests. By default, fields with empty or default values are
273 // omitted from API requests. See
274 // https://pkg.go.dev/google.golang.org/api#hdr-ForceSendFields for more
275 // details.
276 ForceSendFields []string `json:"-"`
277 // NullFields is a list of field names (e.g. "AmpUrls") to include in API
278 // requests with the JSON null value. By default, fields with empty values are
279 // omitted from API requests. See
280 // https://pkg.go.dev/google.golang.org/api#hdr-NullFields for more details.
281 NullFields []string `json:"-"`
282 }
283
284 func (s BatchGetAmpUrlsResponse) MarshalJSON() ([]byte, error) {
285 type NoMethod BatchGetAmpUrlsResponse
286 return gensupport.MarshalJSON(NoMethod(s), s.ForceSendFields, s.NullFields)
287 }
288
289 type AmpUrlsBatchGetCall struct {
290 s *Service
291 batchgetampurlsrequest *BatchGetAmpUrlsRequest
292 urlParams_ gensupport.URLParams
293 ctx_ context.Context
294 header_ http.Header
295 }
296
297 // BatchGet: Returns AMP URL(s) and equivalent AMP Cache URL(s)
298 // (/amp/cache/overview#amp-cache-url-format).
299 func (r *AmpUrlsService) BatchGet(batchgetampurlsrequest *BatchGetAmpUrlsRequest) *AmpUrlsBatchGetCall {
300 c := &AmpUrlsBatchGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
301 c.batchgetampurlsrequest = batchgetampurlsrequest
302 return c
303 }
304
305 // Fields allows partial responses to be retrieved. See
306 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more
307 // details.
308 func (c *AmpUrlsBatchGetCall) Fields(s ...googleapi.Field) *AmpUrlsBatchGetCall {
309 c.urlParams_.Set("fields", googleapi.CombineFields(s))
310 return c
311 }
312
313 // Context sets the context to be used in this call's Do method.
314 func (c *AmpUrlsBatchGetCall) Context(ctx context.Context) *AmpUrlsBatchGetCall {
315 c.ctx_ = ctx
316 return c
317 }
318
319 // Header returns a http.Header that can be modified by the caller to add
320 // headers to the request.
321 func (c *AmpUrlsBatchGetCall) Header() http.Header {
322 if c.header_ == nil {
323 c.header_ = make(http.Header)
324 }
325 return c.header_
326 }
327
328 func (c *AmpUrlsBatchGetCall) doRequest(alt string) (*http.Response, error) {
329 reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_)
330 body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.batchgetampurlsrequest)
331 if err != nil {
332 return nil, err
333 }
334 c.urlParams_.Set("alt", alt)
335 c.urlParams_.Set("prettyPrint", "false")
336 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/ampUrls:batchGet")
337 urls += "?" + c.urlParams_.Encode()
338 req, err := http.NewRequest("POST", urls, body)
339 if err != nil {
340 return nil, err
341 }
342 req.Header = reqHeaders
343 c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "acceleratedmobilepageurl.ampUrls.batchGet", "request", internallog.HTTPRequest(req, body.Bytes()))
344 return gensupport.SendRequest(c.ctx_, c.s.client, req)
345 }
346
347 // Do executes the "acceleratedmobilepageurl.ampUrls.batchGet" call.
348 // Any non-2xx status code is an error. Response headers are in either
349 // *BatchGetAmpUrlsResponse.ServerResponse.Header or (if a response was
350 // returned at all) in error.(*googleapi.Error).Header. Use
351 // googleapi.IsNotModified to check whether the returned error was because
352 // http.StatusNotModified was returned.
353 func (c *AmpUrlsBatchGetCall) Do(opts ...googleapi.CallOption) (*BatchGetAmpUrlsResponse, error) {
354 gensupport.SetOptions(c.urlParams_, opts...)
355 res, err := c.doRequest("json")
356 if res != nil && res.StatusCode == http.StatusNotModified {
357 if res.Body != nil {
358 res.Body.Close()
359 }
360 return nil, gensupport.WrapError(&googleapi.Error{
361 Code: res.StatusCode,
362 Header: res.Header,
363 })
364 }
365 if err != nil {
366 return nil, err
367 }
368 defer googleapi.CloseBody(res)
369 if err := googleapi.CheckResponse(res); err != nil {
370 return nil, gensupport.WrapError(err)
371 }
372 ret := &BatchGetAmpUrlsResponse{
373 ServerResponse: googleapi.ServerResponse{
374 Header: res.Header,
375 HTTPStatusCode: res.StatusCode,
376 },
377 }
378 target := &ret
379 b, err := gensupport.DecodeResponseBytes(target, res)
380 if err != nil {
381 return nil, err
382 }
383 c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "acceleratedmobilepageurl.ampUrls.batchGet", "response", internallog.HTTPResponse(res, b))
384 return ret, nil
385 }