1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17package cx
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	"cloud.google.com/go/longrunning"
27	lroauto "cloud.google.com/go/longrunning/autogen"
28	"github.com/golang/protobuf/proto"
29	structpb "github.com/golang/protobuf/ptypes/struct"
30	gax "github.com/googleapis/gax-go/v2"
31	"google.golang.org/api/iterator"
32	"google.golang.org/api/option"
33	"google.golang.org/api/option/internaloption"
34	gtransport "google.golang.org/api/transport/grpc"
35	cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3"
36	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
37	"google.golang.org/grpc"
38	"google.golang.org/grpc/codes"
39	"google.golang.org/grpc/metadata"
40)
41
42var newEnvironmentsClientHook clientHook
43
44// EnvironmentsCallOptions contains the retry settings for each method of EnvironmentsClient.
45type EnvironmentsCallOptions struct {
46	ListEnvironments         []gax.CallOption
47	GetEnvironment           []gax.CallOption
48	CreateEnvironment        []gax.CallOption
49	UpdateEnvironment        []gax.CallOption
50	DeleteEnvironment        []gax.CallOption
51	LookupEnvironmentHistory []gax.CallOption
52}
53
54func defaultEnvironmentsClientOptions() []option.ClientOption {
55	return []option.ClientOption{
56		internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"),
57		internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"),
58		internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"),
59		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
60		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
61		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
62			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
63	}
64}
65
66func defaultEnvironmentsCallOptions() *EnvironmentsCallOptions {
67	return &EnvironmentsCallOptions{
68		ListEnvironments: []gax.CallOption{
69			gax.WithRetry(func() gax.Retryer {
70				return gax.OnCodes([]codes.Code{
71					codes.Unavailable,
72				}, gax.Backoff{
73					Initial:    100 * time.Millisecond,
74					Max:        60000 * time.Millisecond,
75					Multiplier: 1.30,
76				})
77			}),
78		},
79		GetEnvironment: []gax.CallOption{
80			gax.WithRetry(func() gax.Retryer {
81				return gax.OnCodes([]codes.Code{
82					codes.Unavailable,
83				}, gax.Backoff{
84					Initial:    100 * time.Millisecond,
85					Max:        60000 * time.Millisecond,
86					Multiplier: 1.30,
87				})
88			}),
89		},
90		CreateEnvironment: []gax.CallOption{
91			gax.WithRetry(func() gax.Retryer {
92				return gax.OnCodes([]codes.Code{
93					codes.Unavailable,
94				}, gax.Backoff{
95					Initial:    100 * time.Millisecond,
96					Max:        60000 * time.Millisecond,
97					Multiplier: 1.30,
98				})
99			}),
100		},
101		UpdateEnvironment: []gax.CallOption{
102			gax.WithRetry(func() gax.Retryer {
103				return gax.OnCodes([]codes.Code{
104					codes.Unavailable,
105				}, gax.Backoff{
106					Initial:    100 * time.Millisecond,
107					Max:        60000 * time.Millisecond,
108					Multiplier: 1.30,
109				})
110			}),
111		},
112		DeleteEnvironment: []gax.CallOption{
113			gax.WithRetry(func() gax.Retryer {
114				return gax.OnCodes([]codes.Code{
115					codes.Unavailable,
116				}, gax.Backoff{
117					Initial:    100 * time.Millisecond,
118					Max:        60000 * time.Millisecond,
119					Multiplier: 1.30,
120				})
121			}),
122		},
123		LookupEnvironmentHistory: []gax.CallOption{
124			gax.WithRetry(func() gax.Retryer {
125				return gax.OnCodes([]codes.Code{
126					codes.Unavailable,
127				}, gax.Backoff{
128					Initial:    100 * time.Millisecond,
129					Max:        60000 * time.Millisecond,
130					Multiplier: 1.30,
131				})
132			}),
133		},
134	}
135}
136
137// EnvironmentsClient is a client for interacting with Dialogflow API.
138//
139// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
140type EnvironmentsClient struct {
141	// Connection pool of gRPC connections to the service.
142	connPool gtransport.ConnPool
143
144	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
145	disableDeadlines bool
146
147	// The gRPC API client.
148	environmentsClient cxpb.EnvironmentsClient
149
150	// LROClient is used internally to handle longrunning operations.
151	// It is exposed so that its CallOptions can be modified if required.
152	// Users should not Close this client.
153	LROClient *lroauto.OperationsClient
154
155	// The call options for this service.
156	CallOptions *EnvironmentsCallOptions
157
158	// The x-goog-* metadata to be sent with each request.
159	xGoogMetadata metadata.MD
160}
161
162// NewEnvironmentsClient creates a new environments client.
163//
164// Service for managing Environments.
165func NewEnvironmentsClient(ctx context.Context, opts ...option.ClientOption) (*EnvironmentsClient, error) {
166	clientOpts := defaultEnvironmentsClientOptions()
167
168	if newEnvironmentsClientHook != nil {
169		hookOpts, err := newEnvironmentsClientHook(ctx, clientHookParams{})
170		if err != nil {
171			return nil, err
172		}
173		clientOpts = append(clientOpts, hookOpts...)
174	}
175
176	disableDeadlines, err := checkDisableDeadlines()
177	if err != nil {
178		return nil, err
179	}
180
181	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
182	if err != nil {
183		return nil, err
184	}
185	c := &EnvironmentsClient{
186		connPool:         connPool,
187		disableDeadlines: disableDeadlines,
188		CallOptions:      defaultEnvironmentsCallOptions(),
189
190		environmentsClient: cxpb.NewEnvironmentsClient(connPool),
191	}
192	c.setGoogleClientInfo()
193
194	c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
195	if err != nil {
196		// This error "should not happen", since we are just reusing old connection pool
197		// and never actually need to dial.
198		// If this does happen, we could leak connp. However, we cannot close conn:
199		// If the user invoked the constructor with option.WithGRPCConn,
200		// we would close a connection that's still in use.
201		// TODO: investigate error conditions.
202		return nil, err
203	}
204	return c, nil
205}
206
207// Connection returns a connection to the API service.
208//
209// Deprecated.
210func (c *EnvironmentsClient) Connection() *grpc.ClientConn {
211	return c.connPool.Conn()
212}
213
214// Close closes the connection to the API service. The user should invoke this when
215// the client is no longer required.
216func (c *EnvironmentsClient) Close() error {
217	return c.connPool.Close()
218}
219
220// setGoogleClientInfo sets the name and version of the application in
221// the `x-goog-api-client` header passed on each request. Intended for
222// use by Google-written clients.
223func (c *EnvironmentsClient) setGoogleClientInfo(keyval ...string) {
224	kv := append([]string{"gl-go", versionGo()}, keyval...)
225	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
226	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
227}
228
229// ListEnvironments returns the list of all environments in the specified Agent.
230func (c *EnvironmentsClient) ListEnvironments(ctx context.Context, req *cxpb.ListEnvironmentsRequest, opts ...gax.CallOption) *EnvironmentIterator {
231	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
232	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
233	opts = append(c.CallOptions.ListEnvironments[0:len(c.CallOptions.ListEnvironments):len(c.CallOptions.ListEnvironments)], opts...)
234	it := &EnvironmentIterator{}
235	req = proto.Clone(req).(*cxpb.ListEnvironmentsRequest)
236	it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Environment, string, error) {
237		var resp *cxpb.ListEnvironmentsResponse
238		req.PageToken = pageToken
239		if pageSize > math.MaxInt32 {
240			req.PageSize = math.MaxInt32
241		} else {
242			req.PageSize = int32(pageSize)
243		}
244		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
245			var err error
246			resp, err = c.environmentsClient.ListEnvironments(ctx, req, settings.GRPC...)
247			return err
248		}, opts...)
249		if err != nil {
250			return nil, "", err
251		}
252
253		it.Response = resp
254		return resp.GetEnvironments(), resp.GetNextPageToken(), nil
255	}
256	fetch := func(pageSize int, pageToken string) (string, error) {
257		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
258		if err != nil {
259			return "", err
260		}
261		it.items = append(it.items, items...)
262		return nextPageToken, nil
263	}
264	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
265	it.pageInfo.MaxSize = int(req.GetPageSize())
266	it.pageInfo.Token = req.GetPageToken()
267	return it
268}
269
270// GetEnvironment retrieves the specified Environment.
271func (c *EnvironmentsClient) GetEnvironment(ctx context.Context, req *cxpb.GetEnvironmentRequest, opts ...gax.CallOption) (*cxpb.Environment, error) {
272	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
273		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
274		defer cancel()
275		ctx = cctx
276	}
277	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
278	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
279	opts = append(c.CallOptions.GetEnvironment[0:len(c.CallOptions.GetEnvironment):len(c.CallOptions.GetEnvironment)], opts...)
280	var resp *cxpb.Environment
281	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
282		var err error
283		resp, err = c.environmentsClient.GetEnvironment(ctx, req, settings.GRPC...)
284		return err
285	}, opts...)
286	if err != nil {
287		return nil, err
288	}
289	return resp, nil
290}
291
292// CreateEnvironment creates an Environment in the specified Agent.
293func (c *EnvironmentsClient) CreateEnvironment(ctx context.Context, req *cxpb.CreateEnvironmentRequest, opts ...gax.CallOption) (*CreateEnvironmentOperation, error) {
294	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
295		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
296		defer cancel()
297		ctx = cctx
298	}
299	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
300	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
301	opts = append(c.CallOptions.CreateEnvironment[0:len(c.CallOptions.CreateEnvironment):len(c.CallOptions.CreateEnvironment)], opts...)
302	var resp *longrunningpb.Operation
303	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
304		var err error
305		resp, err = c.environmentsClient.CreateEnvironment(ctx, req, settings.GRPC...)
306		return err
307	}, opts...)
308	if err != nil {
309		return nil, err
310	}
311	return &CreateEnvironmentOperation{
312		lro: longrunning.InternalNewOperation(c.LROClient, resp),
313	}, nil
314}
315
316// UpdateEnvironment updates the specified Environment.
317func (c *EnvironmentsClient) UpdateEnvironment(ctx context.Context, req *cxpb.UpdateEnvironmentRequest, opts ...gax.CallOption) (*UpdateEnvironmentOperation, error) {
318	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
319		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
320		defer cancel()
321		ctx = cctx
322	}
323	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "environment.name", url.QueryEscape(req.GetEnvironment().GetName())))
324	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
325	opts = append(c.CallOptions.UpdateEnvironment[0:len(c.CallOptions.UpdateEnvironment):len(c.CallOptions.UpdateEnvironment)], opts...)
326	var resp *longrunningpb.Operation
327	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
328		var err error
329		resp, err = c.environmentsClient.UpdateEnvironment(ctx, req, settings.GRPC...)
330		return err
331	}, opts...)
332	if err != nil {
333		return nil, err
334	}
335	return &UpdateEnvironmentOperation{
336		lro: longrunning.InternalNewOperation(c.LROClient, resp),
337	}, nil
338}
339
340// DeleteEnvironment deletes the specified Environment.
341func (c *EnvironmentsClient) DeleteEnvironment(ctx context.Context, req *cxpb.DeleteEnvironmentRequest, opts ...gax.CallOption) error {
342	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
343		cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond)
344		defer cancel()
345		ctx = cctx
346	}
347	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
348	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
349	opts = append(c.CallOptions.DeleteEnvironment[0:len(c.CallOptions.DeleteEnvironment):len(c.CallOptions.DeleteEnvironment)], opts...)
350	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
351		var err error
352		_, err = c.environmentsClient.DeleteEnvironment(ctx, req, settings.GRPC...)
353		return err
354	}, opts...)
355	return err
356}
357
358// LookupEnvironmentHistory looks up the history of the specified Environment.
359func (c *EnvironmentsClient) LookupEnvironmentHistory(ctx context.Context, req *cxpb.LookupEnvironmentHistoryRequest, opts ...gax.CallOption) *EnvironmentIterator {
360	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
361	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
362	opts = append(c.CallOptions.LookupEnvironmentHistory[0:len(c.CallOptions.LookupEnvironmentHistory):len(c.CallOptions.LookupEnvironmentHistory)], opts...)
363	it := &EnvironmentIterator{}
364	req = proto.Clone(req).(*cxpb.LookupEnvironmentHistoryRequest)
365	it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Environment, string, error) {
366		var resp *cxpb.LookupEnvironmentHistoryResponse
367		req.PageToken = pageToken
368		if pageSize > math.MaxInt32 {
369			req.PageSize = math.MaxInt32
370		} else {
371			req.PageSize = int32(pageSize)
372		}
373		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
374			var err error
375			resp, err = c.environmentsClient.LookupEnvironmentHistory(ctx, req, settings.GRPC...)
376			return err
377		}, opts...)
378		if err != nil {
379			return nil, "", err
380		}
381
382		it.Response = resp
383		return resp.GetEnvironments(), resp.GetNextPageToken(), nil
384	}
385	fetch := func(pageSize int, pageToken string) (string, error) {
386		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
387		if err != nil {
388			return "", err
389		}
390		it.items = append(it.items, items...)
391		return nextPageToken, nil
392	}
393	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
394	it.pageInfo.MaxSize = int(req.GetPageSize())
395	it.pageInfo.Token = req.GetPageToken()
396	return it
397}
398
399// CreateEnvironmentOperation manages a long-running operation from CreateEnvironment.
400type CreateEnvironmentOperation struct {
401	lro *longrunning.Operation
402}
403
404// CreateEnvironmentOperation returns a new CreateEnvironmentOperation from a given name.
405// The name must be that of a previously created CreateEnvironmentOperation, possibly from a different process.
406func (c *EnvironmentsClient) CreateEnvironmentOperation(name string) *CreateEnvironmentOperation {
407	return &CreateEnvironmentOperation{
408		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
409	}
410}
411
412// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
413//
414// See documentation of Poll for error-handling information.
415func (op *CreateEnvironmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) {
416	var resp cxpb.Environment
417	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
418		return nil, err
419	}
420	return &resp, nil
421}
422
423// Poll fetches the latest state of the long-running operation.
424//
425// Poll also fetches the latest metadata, which can be retrieved by Metadata.
426//
427// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
428// the operation has completed with failure, the error is returned and op.Done will return true.
429// If Poll succeeds and the operation has completed successfully,
430// op.Done will return true, and the response of the operation is returned.
431// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
432func (op *CreateEnvironmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) {
433	var resp cxpb.Environment
434	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
435		return nil, err
436	}
437	if !op.Done() {
438		return nil, nil
439	}
440	return &resp, nil
441}
442
443// Metadata returns metadata associated with the long-running operation.
444// Metadata itself does not contact the server, but Poll does.
445// To get the latest metadata, call this method after a successful call to Poll.
446// If the metadata is not available, the returned metadata and error are both nil.
447func (op *CreateEnvironmentOperation) Metadata() (*structpb.Struct, error) {
448	var meta structpb.Struct
449	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
450		return nil, nil
451	} else if err != nil {
452		return nil, err
453	}
454	return &meta, nil
455}
456
457// Done reports whether the long-running operation has completed.
458func (op *CreateEnvironmentOperation) Done() bool {
459	return op.lro.Done()
460}
461
462// Name returns the name of the long-running operation.
463// The name is assigned by the server and is unique within the service from which the operation is created.
464func (op *CreateEnvironmentOperation) Name() string {
465	return op.lro.Name()
466}
467
468// UpdateEnvironmentOperation manages a long-running operation from UpdateEnvironment.
469type UpdateEnvironmentOperation struct {
470	lro *longrunning.Operation
471}
472
473// UpdateEnvironmentOperation returns a new UpdateEnvironmentOperation from a given name.
474// The name must be that of a previously created UpdateEnvironmentOperation, possibly from a different process.
475func (c *EnvironmentsClient) UpdateEnvironmentOperation(name string) *UpdateEnvironmentOperation {
476	return &UpdateEnvironmentOperation{
477		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
478	}
479}
480
481// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
482//
483// See documentation of Poll for error-handling information.
484func (op *UpdateEnvironmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) {
485	var resp cxpb.Environment
486	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
487		return nil, err
488	}
489	return &resp, nil
490}
491
492// Poll fetches the latest state of the long-running operation.
493//
494// Poll also fetches the latest metadata, which can be retrieved by Metadata.
495//
496// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
497// the operation has completed with failure, the error is returned and op.Done will return true.
498// If Poll succeeds and the operation has completed successfully,
499// op.Done will return true, and the response of the operation is returned.
500// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
501func (op *UpdateEnvironmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) {
502	var resp cxpb.Environment
503	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
504		return nil, err
505	}
506	if !op.Done() {
507		return nil, nil
508	}
509	return &resp, nil
510}
511
512// Metadata returns metadata associated with the long-running operation.
513// Metadata itself does not contact the server, but Poll does.
514// To get the latest metadata, call this method after a successful call to Poll.
515// If the metadata is not available, the returned metadata and error are both nil.
516func (op *UpdateEnvironmentOperation) Metadata() (*structpb.Struct, error) {
517	var meta structpb.Struct
518	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
519		return nil, nil
520	} else if err != nil {
521		return nil, err
522	}
523	return &meta, nil
524}
525
526// Done reports whether the long-running operation has completed.
527func (op *UpdateEnvironmentOperation) Done() bool {
528	return op.lro.Done()
529}
530
531// Name returns the name of the long-running operation.
532// The name is assigned by the server and is unique within the service from which the operation is created.
533func (op *UpdateEnvironmentOperation) Name() string {
534	return op.lro.Name()
535}
536
537// EnvironmentIterator manages a stream of *cxpb.Environment.
538type EnvironmentIterator struct {
539	items    []*cxpb.Environment
540	pageInfo *iterator.PageInfo
541	nextFunc func() error
542
543	// Response is the raw response for the current page.
544	// It must be cast to the RPC response type.
545	// Calling Next() or InternalFetch() updates this value.
546	Response interface{}
547
548	// InternalFetch is for use by the Google Cloud Libraries only.
549	// It is not part of the stable interface of this package.
550	//
551	// InternalFetch returns results from a single call to the underlying RPC.
552	// The number of results is no greater than pageSize.
553	// If there are no more results, nextPageToken is empty and err is nil.
554	InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Environment, nextPageToken string, err error)
555}
556
557// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
558func (it *EnvironmentIterator) PageInfo() *iterator.PageInfo {
559	return it.pageInfo
560}
561
562// Next returns the next result. Its second return value is iterator.Done if there are no more
563// results. Once Next returns Done, all subsequent calls will return Done.
564func (it *EnvironmentIterator) Next() (*cxpb.Environment, error) {
565	var item *cxpb.Environment
566	if err := it.nextFunc(); err != nil {
567		return item, err
568	}
569	item = it.items[0]
570	it.items = it.items[1:]
571	return item, nil
572}
573
574func (it *EnvironmentIterator) bufLen() int {
575	return len(it.items)
576}
577
578func (it *EnvironmentIterator) takeBuf() interface{} {
579	b := it.items
580	it.items = nil
581	return b
582}
583