github.com/opensearch-project/opensearch-go/v2@v2.3.0/opensearchapi/opensearchapi.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  //
     3  // The OpenSearch Contributors require contributions made to
     4  // this file be licensed under the Apache-2.0 license or a
     5  // compatible open source license.
     6  //
     7  // Modifications Copyright OpenSearch Contributors. See
     8  // GitHub history for details.
     9  
    10  // Licensed to Elasticsearch B.V. under one or more contributor
    11  // license agreements. See the NOTICE file distributed with
    12  // this work for additional information regarding copyright
    13  // ownership. Elasticsearch B.V. licenses this file to you under
    14  // the Apache License, Version 2.0 (the "License"); you may
    15  // not use this file except in compliance with the License.
    16  // You may obtain a copy of the License at
    17  //
    18  //    http://www.apache.org/licenses/LICENSE-2.0
    19  //
    20  // Unless required by applicable law or agreed to in writing,
    21  // software distributed under the License is distributed on an
    22  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    23  // KIND, either express or implied.  See the License for the
    24  // specific language governing permissions and limitations
    25  // under the License.
    26  
    27  package opensearchapi
    28  
    29  import (
    30  	"net/http"
    31  	"strconv"
    32  	"time"
    33  
    34  	"github.com/opensearch-project/opensearch-go/v2/internal/version"
    35  )
    36  
    37  // Version returns the package version as a string.
    38  //
    39  const Version = version.Client
    40  
    41  // Transport defines the interface for an API client.
    42  //
    43  type Transport interface {
    44  	Perform(*http.Request) (*http.Response, error)
    45  }
    46  
    47  // BoolPtr returns a pointer to v.
    48  //
    49  // It is used as a convenience function for converting a bool value
    50  // into a pointer when passing the value to a function or struct field
    51  // which expects a pointer.
    52  //
    53  func BoolPtr(v bool) *bool { return &v }
    54  
    55  // IntPtr returns a pointer to v.
    56  //
    57  // It is used as a convenience function for converting an int value
    58  // into a pointer when passing the value to a function or struct field
    59  // which expects a pointer.
    60  //
    61  func IntPtr(v int) *int { return &v }
    62  
    63  // formatDuration converts duration to a string in the format
    64  // accepted by Elasticsearch.
    65  //
    66  func formatDuration(d time.Duration) string {
    67  	if d < time.Millisecond {
    68  		return strconv.FormatInt(int64(d), 10) + "nanos"
    69  	}
    70  	return strconv.FormatInt(int64(d)/int64(time.Millisecond), 10) + "ms"
    71  }