...

Source file src/google.golang.org/api/internal/examples/mock/lowlevel.go

Documentation: google.golang.org/api/internal/examples/mock

     1  // Copyright 2021 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  package mock
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"google.golang.org/api/googleapi"
    11  	"google.golang.org/api/translate/v3"
    12  )
    13  
    14  // TranslateTextCall is used to translate text and is fullfilled by a
    15  // `translate.ProjectsTranslateTextCall`.
    16  type TranslateTextCall interface {
    17  	Do(opts ...googleapi.CallOption) (*translate.TranslateTextResponse, error)
    18  }
    19  
    20  // TranslateTextLowLevel executes the call and returns the translated text.
    21  func TranslateTextLowLevel(call TranslateTextCall) (string, error) {
    22  	resp, err := call.Do()
    23  	if err != nil {
    24  		return "", fmt.Errorf("unable to translate text: %v", err)
    25  	}
    26  	return resp.Translations[0].TranslatedText, nil
    27  }
    28  

View as plain text